Skip to content

Instantly share code, notes, and snippets.

@sodik82
Forked from alobato/start-stop-example.sh
Last active February 27, 2016 22:48
Show Gist options
  • Save sodik82/4f4aafdb52e84102b75d to your computer and use it in GitHub Desktop.
Save sodik82/4f4aafdb52e84102b75d to your computer and use it in GitHub Desktop.
start-stop-example
#!/bin/sh
set -e
. /lib/lsb/init-functions
# Must be a valid filename
NAME=tesco
PIDFILE=/run/$NAME.pid
#This is the command to be run, give the full pathname
DAEMON=/var/lib/jenkins/.nvm/versions/node/v4.2.4/bin/node
DAEMON_OPTS="server.js"
USER=jenkins
WORK_DIR=/opt/node_app
export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
case "$1" in
start)
echo -n "Starting daemon: "$NAME
start-stop-daemon --start --quiet -b -m --pidfile $PIDFILE --chdir $WORK_DIR --chuid $USER --exec $DAEMON -- $DAEMON_OPTS
echo "."
;;
stop)
echo -n "Stopping daemon: "$NAME
start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE
echo "."
;;
restart)
echo -n "Restarting daemon: "$NAME
start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile $PIDFILE
start-stop-daemon --start --quiet -b -m --pidfile $PIDFILE --chdir $WORK_DIR --chuid $USER --exec $DAEMON -- $DAEMON_OPTS
echo "."
;;
status)
status_of_proc -p $PIDFILE $DAEMON $NAME && exit 0 || exit $?
;;
*)
echo "Usage: "$1" {start|stop|restart}"
exit 1
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment