-
-
Save tomcbe/1e965219958aec15fd85e8fc9d978e31 to your computer and use it in GitHub Desktop.
start-stop-daemon script for java application
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 | |
DESC="Java Service" | |
NAME=java-service | |
PIDFILE=/tmp/$NAME.pid | |
PATH_TO_JAR=~/java-service.jar | |
PATH_TO_JAVA=/usr/local/jdk1.8.0_131/bin/java | |
SERVICE_CONFIG='-Dserver.port=8080 -DLOG_PATH=/var/log' | |
COMMAND="$PATH_TO_JAVA -- $SERVICE_CONFIG -jar $PATH_TO_JAR" | |
d_start() { | |
start-stop-daemon --start --quiet --background --make-pidfile --pidfile $PIDFILE --exec $COMMAND | |
} | |
d_stop() { | |
start-stop-daemon --stop --quiet --pidfile $PIDFILE | |
if [ -e $PIDFILE ] | |
then rm $PIDFILE | |
fi | |
} | |
case $1 in | |
start) | |
echo -n "Starting $DESC: $NAME" | |
d_start | |
echo "." | |
;; | |
stop) | |
echo -n "Stopping $DESC: $NAME" | |
d_stop | |
echo "." | |
;; | |
restart) | |
echo -n "Restarting $DESC: $NAME" | |
d_stop | |
sleep 1 | |
d_start | |
echo "." | |
;; | |
*) | |
echo "usage: $NAME {start|stop|restart}" | |
exit 1 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment