Last active
December 17, 2015 12:29
-
-
Save haiiro-shimeji/5610159 to your computer and use it in GitHub Desktop.
Simple example of init script. This is a script starting JsTestDriver Daemon
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/bash | |
| NAME=JsTestDriver | |
| USER=ikeda | |
| DESC="JsTestDriber daemon" | |
| JAVA=/usr/bin/java | |
| PORT=4224 | |
| PATH=/usr/local/share/${NAME} | |
| PIDFILE=${PATH}/${NAME}.pid | |
| check_process() | |
| { | |
| if [ -e $PIDFILE ] | |
| then | |
| kill -0 `/bin/cat $PIDFILE` | |
| else | |
| return 1 | |
| fi | |
| } | |
| start() | |
| { | |
| check_process | |
| if [ 0 -eq $? ] | |
| then | |
| echo " already running." | |
| else | |
| (/usr/bin/setsid /sbin/start-stop-daemon --start --oknodo -m --pidfile $PIDFILE --chuid $USER --user $USER --name $NAME --quiet --exec $JAVA -- -jar ${PATH}/${NAME}.jar --port $PORT) & | |
| echo "$NAME." | |
| fi | |
| } | |
| stop() | |
| { | |
| check_process | |
| if [ 0 -eq $? ] | |
| then | |
| /sbin/start-stop-daemon --stop --user $USER --pidfile $PIDFILE --retry 5 | |
| /bin/rm -f $PIDFILE | |
| else | |
| echo "$NAME is not running." | |
| fi | |
| } | |
| case "$1" in | |
| status) | |
| ;; | |
| start) | |
| start | |
| ;; | |
| stop) | |
| stop | |
| ;; | |
| restart) | |
| stop | |
| start | |
| ;; | |
| *) | |
| exit 1 | |
| esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment