73 lines
1.6 KiB
Plaintext
73 lines
1.6 KiB
Plaintext
|
#!/bin/sh
|
||
|
# start/stop/restart ungit daemon:
|
||
|
PLG="ungit"
|
||
|
EMHTTP="/usr/local/emhttp/plugins/$PLG"
|
||
|
PROG="$EMHTTP/node_modules/$PLG/src/server.js"
|
||
|
LOCKFILE="/var/lock/$PLG"
|
||
|
PIDFILE="/var/run/$PLG.pid"
|
||
|
CONFIG="/boot/config/plugins/$PLG/$PLG.cfg"
|
||
|
|
||
|
# read our configuration
|
||
|
[ -e "$CONFIG" ] && source "$CONFIG"
|
||
|
|
||
|
# Start ungit:
|
||
|
ungit_start() {
|
||
|
# no-op if already running
|
||
|
if [ ! -r "$PIDFILE" ]; then
|
||
|
if [ "$DAEMON" == "enable" ]; then
|
||
|
echo "starting $PLG..."
|
||
|
sleep 1
|
||
|
#cd $EMHTTP/node_modules/$PLG
|
||
|
nohup /usr/bin/node $PROG --port="$PORT" --logDirectory="/var/log/" --logGitCommands --logGitOutput >/var/log/$PLG 2>&1 | echo $! > $PIDFILE &
|
||
|
touch $LOCKFILE
|
||
|
TIMER=0
|
||
|
while [ ! -e $PIDFILE ]; do
|
||
|
sleep 1
|
||
|
let TIMER=$TIMER+1
|
||
|
if [ $TIMER -gt 5 ]; then
|
||
|
echo -n "$PIDFILE not created"
|
||
|
break
|
||
|
fi
|
||
|
done
|
||
|
else
|
||
|
echo "$PLG is not enabled "
|
||
|
fi
|
||
|
else
|
||
|
echo "$PLG is running "
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
# Stop ungit:
|
||
|
ungit_stop() {
|
||
|
# no-op if not running
|
||
|
if [ -r $PIDFILE ]; then
|
||
|
#stop ungit
|
||
|
echo "stopping $PLG..."
|
||
|
sleep 1
|
||
|
kill $(cat $PIDFILE)
|
||
|
rm -f $LOCKFILE && rm -f $PIDFILE
|
||
|
else
|
||
|
echo "$PLG is stopped "
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
# Restart ungit:
|
||
|
ungit_restart() {
|
||
|
ungit_stop
|
||
|
sleep 1
|
||
|
ungit_start
|
||
|
}
|
||
|
|
||
|
case "$1" in
|
||
|
'start')
|
||
|
ungit_start
|
||
|
;;
|
||
|
'stop')
|
||
|
ungit_stop
|
||
|
;;
|
||
|
'restart')
|
||
|
ungit_restart
|
||
|
;;
|
||
|
*)
|
||
|
echo "usage rc.ungit: start|stop|restart"
|
||
|
esac
|