-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlinuxService
executable file
·138 lines (129 loc) · 3.53 KB
/
linuxService
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/bash
# An init.d script for running a Node.js process as a service using Forever as
# the process monitor. For more configuration options associated with Forever,
# see: https://github.com/nodejitsu/forever
#
# Live: This shell script takes care of starting and stopping the Kaltura kLive Controller service
#
# chkconfig: 2345 85 15
# description: Kaltura Live Controller
### BEGIN INIT INFO
# Provides: kLiveController
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# X-Interactive: true
# Short-Description: Start/stop Kaltura Live Controller
### END INIT INFO
NAME="kCrashServer"
KLIVE_CONTROLLER_PREFIX="/opt/kaltura/mini-breakpad-server/"
NODE_PATH="$KLIVE_CONTROLLER_PREFIX/node_modules"
FOREVER="$NODE_PATH/forever/bin/forever"
APPLICATION_PATH="$KLIVE_CONTROLLER_PREFIX/bin/mini-breakpad-server"
LOG_DIR="/var/log/kCrashServer"
PID_DIR="/var/run"
MIN_UPTIME="5000"
SPIN_SLEEP_TIME="2000"
export PATH=$PATH:$NODE_PATH/forever/bin:/usr/local/bin
HOME=${HOME:-~}
loadNvm() {
# This loads nvm
cd $KLIVE_CONTROLLER_PREFIX
[ -z "$NVM_DIR" ] && NVM_DIR="$HOME/.nvm"
if [ -s "$NVM_DIR/nvm.sh" ] ; then
source "$NVM_DIR/nvm.sh"
if [ -s .nvmrc ] ; then
nvm use || nvm install
else
echo "no .nvmrc in $PWD , Exiting"
exit 1
fi
else
echo "nvm not found in $NVM_DIR, this is a must, Exiting!"
exit 1
fi
}
start() {
[ -d ${LOG_DIR} ] || mkdir -p ${LOG_DIR}
loadNvm
RETVAL=0
PIDFILE="$PID_DIR/${NAME}.pid"
LOGFILE="$LOG_DIR/${NAME}-forever.log"
if [ -f $PIDFILE ]; then
echo "${NAME} already running"
else
echo "Starting ${NAME}"
$FOREVER \
--pidFile $PIDFILE \
-a \
-l $LOGFILE \
--minUptime $MIN_UPTIME \
--spinSleepTime $SPIN_SLEEP_TIME \
--workingDir $KLIVE_CONTROLLER_PREFIX \
start $APPLICATION_PATH
RETVAL=$(( $RETVAL + $? ))
fi
}
stop() {
loadNvm
RETVAL=0
PIDFILE="$PID_DIR/${NAME}.pid"
if [ -f $PIDFILE ]; then
echo "Shutting down ${NAME}"
# Tell Forever to stop the process.
$FOREVER stop $( cat $PIDFILE )
RETVAL=$(( $RETVAL + $? ))
# Get rid of the pidfile, since Forever won't do that.
else
echo "${NAME}_ is not running."
fi
}
restart() {
stop
start
}
status() {
RETVAL=0
PIDFILE="$PID_DIR/${NAME}.pid"
if [ -f $PIDFILE ] ; then
VAL=$( ( cat ${PIDFILE} | xargs ps -p ) | wc -l )
if [ $VAL -gt 1 ] ; then
echo "${NAME} is running with PID $( cat $PIDFILE )"
else
echo "${NAME} is not running but there is stale pidFile: $PIDFILE"
RETVAL=$(( $RETVAL + 1 ))
fi
else
echo "${NAME} is not running."
RETVAL=$(( $RETVAL + 1 ))
fi
}
killApp() {
echo "Aggressively kill all Live processes"
pkill -f $APPLICATION_PATH
echo "Remove all PID files"
rm -f ${PID_DIR}/${NAME}*.pid
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
restart
;;
kill)
killApp
;;
*)
echo "Usage: {start|stop|status|restart|kill}"
exit 1
;;
esac
exit $RETVAL