Last active
February 8, 2018 00:37
-
-
Save shaiguitar/6c7778e21d3e54c40735914207d5abfb to your computer and use it in GitHub Desktop.
/etc/init.d/odrive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
### BEGIN INIT INFO | |
# Provides: odrive | |
# Required-Start: $local_fs $network $syslog | |
# Required-Stop: $local_fs $network $syslog | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: odrive init script | |
# Description: odrive server startup sctipt. | |
### END INIT INFO | |
# XXXCHANGEME | |
USER="pi" | |
# XXXCHANGEME | |
APPBIN="$HOME/.odrive-agent/bin/home/pi/hudson/workspace/Odrive_RPi_Agent/dist/odriveagent" | |
NAME="odrive" | |
PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" | |
APPDIR="/" | |
PIDFILE="/var/run/${NAME}-RUNNING.pid" | |
# Include functions | |
set -e | |
. /lib/lsb/init-functions | |
start() { | |
printf "Starting '$NAME'... " | |
start-stop-daemon --chuid $USER --start --background --make-pidfile --pidfile "$PIDFILE" --chdir "$APPDIR" --exec "$APPBIN" || true | |
printf "done\n" | |
} | |
#We need this function to ensure the whole process tree will be killed | |
killtree() { | |
local _pid=$1 | |
local _sig=${2-TERM} | |
for _child in $(ps -o pid --no-headers --ppid ${_pid}); do | |
killtree ${_child} ${_sig} | |
done | |
kill -${_sig} ${_pid} | |
} | |
stop() { | |
printf "Stopping '$NAME'... " | |
[ -z `cat "$PIDFILE" 2>/dev/null` ] || \ | |
while test -d /proc/$(cat "$PIDFILE"); do | |
killtree $(cat "$PIDFILE") 15 | |
sleep 0.5 | |
done | |
[ -z `cat "$PIDFILE" 2>/dev/null` ] || rm "$PIDFILE" | |
printf "done\n" | |
} | |
status() { | |
"$APPBIN" -S | |
} | |
configure() { | |
"$APPBIN" -C | |
} | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
restart) | |
stop | |
start | |
;; | |
status) | |
status | |
;; | |
configure) | |
configure | |
;; | |
*) | |
echo "Usage: $NAME {start|stop|restart|status|configure}" >&2 | |
exit 1 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment