Skip to content

Instantly share code, notes, and snippets.

@kai5263499
Created August 4, 2017 02:44
Show Gist options
  • Save kai5263499/987808b8a502599c10b6191a94cbab51 to your computer and use it in GitHub Desktop.
Save kai5263499/987808b8a502599c10b6191a94cbab51 to your computer and use it in GitHub Desktop.
Simple service daemon
#!/bin/bash
# myapp daemon
# chkconfig: 345 20 80
# description: myapp daemon
# processname: myapp
DAEMON_PATH="/home/wes"
DAEMON=myapp
DAEMONOPTS="-my opts"
NAME=myapp
DESC="My daemon description"
SCRIPTNAME=/etc/init.d/$NAME
case "$1" in
start)
printf "%-50s" "Starting $NAME..."
nohup ${DAEMON_PATH}/${DAEMON} ${DAEMONOPTS} &
printf "%s\n" "Ok"
;;
status)
printf "%-50s" "Checking $NAME..."
if pgrep -f ${DAEMON_PATH}/${NAME} > /dev/null; then
printf "%s\n" "Running"
else
printf "%s\n" "Not running"
fi
;;
stop)
printf "%-50s" "Stopping $NAME"
kill -HUP `pgrep -f $NAME`
printf "%s\n" "Ok"
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: $0 {status|start|stop|restart}"
exit 1
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment