Unraid-SlackPack/source/ungit/etc/rc.d/rc.ungit
2016-11-06 11:17:39 -07:00

82 lines
1.6 KiB
Bash
Executable File

#!/bin/sh
# start/stop/restart ungit daemon:
PLG="ungit"
PROG="/usr/lib64/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
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
}
# Restart ungit:
ungit_update() {
ungit_stop
sleep 1
npm -g update
ungit_start
}
case "$1" in
'start')
ungit_start
;;
'stop')
ungit_stop
;;
'restart')
ungit_restart
;;
'update')
ungit_update
;;
*)
echo "usage rc.ungit: start|stop|restart"
esac