Created
April 7, 2015 19:41
-
-
Save sebboh/2796cbc79c695caa5d82 to your computer and use it in GitHub Desktop.
daemonize service
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 | |
# template inputs: | |
# @service_name: name of the service | |
# @service_cwd: working directory for running the service | |
# @service_cmd: command to run the service | |
start () { | |
echo -n "Starting <%= @service_name %>..." | |
# Start daemon | |
daemon --chdir='<%= @service_cwd %>' --command '<%= @service_cmd %>' --respawn --output=/var/log/<%= @service_name %>/output.log --name=<%= @service_name %> --user=<%= @service_user %> --verbose | |
RETVAL=$? | |
if [ $RETVAL = 0 ] | |
then | |
echo "done." | |
else | |
echo "failed. See error code for more information." | |
fi | |
return $RETVAL | |
} | |
stop () { | |
# Stop daemon | |
echo -n "Stopping <%= @service_name %>..." | |
daemon --stop --name=<%= @service_name %> --user=<%= @service_user %> --verbose | |
RETVAL=$? | |
if [ $RETVAL = 0 ] | |
then | |
echo "Done." | |
else | |
echo "Failed. See error code for more information." | |
fi | |
return $RETVAL | |
} | |
restart () { | |
status | |
RETVAL=$? | |
if [ $RETVAL = 0 ] | |
then | |
stop | |
sleep 2 | |
fi | |
start | |
} | |
status () { | |
# Report on the status of the daemon | |
daemon --running --verbose --user=<%= @service_user %> --name=<%= @service_name %> | |
return $? | |
} | |
case "$1" in | |
start) | |
start | |
;; | |
status) | |
status | |
;; | |
stop) | |
stop | |
;; | |
restart) | |
restart | |
;; | |
*) | |
echo $"Usage: <%= @service_name %> {start|status|stop|restart}" | |
exit 3 | |
;; | |
esac | |
exit $RETVAL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment