Skip to content

Instantly share code, notes, and snippets.

@Sythelux
Created February 11, 2016 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sythelux/7396818810806d4057b6 to your computer and use it in GitHub Desktop.
Save Sythelux/7396818810806d4057b6 to your computer and use it in GitHub Desktop.
debian service Script for jars
#!/bin/sh
# kFreeBSD do not accept scripts as interpreters, using #!/bin/sh and sourcing.
if [ true != "$INIT_D_SCRIPT_SOURCED" ] ; then
set "$0" "$@"; INIT_D_SCRIPT_SOURCED=true . /lib/init/init-d-script
fi
### BEGIN INIT INFO
# Provides: MyApp
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Service that runs MyApp on startup
# Description: This Files starts the MyApp Programm.
### END INIT INFO
# Author: Sythelux Rikd <derSyth@gmail.com>
NAME=MyApp#toChange
APP_ROOT="/path/to/$NAME" #toChange
DESC="service that runs $NAME on startup"
PIDFILE=/var/run/${NAME}.pid
EXECUTABLE=/usr/bin/java
ARGUMENTS="-jar -Djava.library.path=$APP_ROOT/natives/ $APP_ROOT/$NAME.jar"
usage() {
echo "service `basename "$0"` {start|stop|restart|status}"
return 0
}
start(){
${APP_ROOT}/scripts/recreateFiles
start-stop-daemon --pidfile $PIDFILE --make-pidfile --background --chdir $APP_ROOT --startas $EXECUTABLE --start -- $ARGUMENTS
retVal=$?
echo "Starting "${NAME}" "${retVal}
return ${retVal}
}
stop(){
start-stop-daemon --pidfile /var/run/${NAME}.pid --stop
python ${APP_ROOT}/scripts/resetLEDs.py
retVal=$?
echo "Stopping "${NAME}" "${retVal}
rm /var/run/${NAME}.pid
return ${retVal}
}
restart(){
stop
start
}
status(){
start-stop-daemon --pidfile /var/run/${NAME}.pid --status
retVal=$?
case ${retVal} in
0) echo "App ${NAME} running"
;;
1) echo "App ${NAME} not running, but found pid."
;;
2) echo "App ${NAME} not running"
;;
3) echo "App ${NAME} state unknown"
;;
esac
return ${retVal}
}
case $1 in
restart) restart
;;
start) start
;;
stop) stop
;;
status) status
;;
*) usage
;;
esac
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment