Skip to content

Instantly share code, notes, and snippets.

@hedcler
Created March 8, 2018 17:44
Show Gist options
  • Save hedcler/acfd7b633019703b4533b72e332796d1 to your computer and use it in GitHub Desktop.
Save hedcler/acfd7b633019703b4533b72e332796d1 to your computer and use it in GitHub Desktop.
Linux daemon template
#!/bin/bash
SRC_PATH=/path/to
FILE_WO_EXT=filename
case "$1" in
start)
$SRC_PATH/$FILE_WO_EXT.sh &
echo $!>/var/run/$FILE_WO_EXT.pid
;;
stop)
kill -9 `cat /var/run/$FILE_WO_EXT.pid`
rm /var/run/$FILE_WO_EXT.pid
;;
restart)
$0 stop
$0 start
;;
status)
if [ -e /var/run/$FILE_WO_EXT.pid ]; then
echo $FILE_WO_EXT.sh is running, pid=`cat /var/run/$FILE_WO_EXT.pid`
else
echo $FILE_WO_EXT.sh is NOT running
exit 1
fi
;;
*)
echo "Usage: $0 {start|stop|status|restart}"
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment