Skip to content

Instantly share code, notes, and snippets.

@silvioq
Created February 10, 2011 20:10
Show Gist options
  • Save silvioq/821236 to your computer and use it in GitHub Desktop.
Save silvioq/821236 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
#
# Global vars
SERVNAME=example
PIDFILE=/tmp/$SERVNAME.pid
COMMAND=/path/to/binary.sh
USER=root
# Get function from functions library
. /etc/init.d/functions
# Start the service
start() {
echo -n "Starting $SERVNAME server"
status -p $PIDFILE > /dev/null
if [ "$?" = "0" ]
then
echo -n " ... is running"
failure $"$SERVNAMErunning"
echo
exit 1
fi
su - $USER -c "${COMMAND} " &
echo $! > $PIDFILE
### Create the lock file ###
touch /var/lock/subsys/$SERVNAME
success $"$SERVNAME server startup"
echo
}
# Restart the service
stop() {
echo -n "Stopping $SERVNAME server"
killproc -p $PIDFILE
### Now, delete the lock file ###
rm -f /var/lock/subsys/$SERVNAME
echo
}
### main logic ###
case "$1" in
start)
start
;;
stop)
stop
;;
status)
echo -n "$SERVNAME server "
status -p $PIDFILE
exit $?
;;
restart|reload|condrestart)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|status}"
exit 1
esac
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment