Skip to content

Instantly share code, notes, and snippets.

@fisproject
Last active June 3, 2019 10:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fisproject/d968318374bc81d7f468613a8205c1cd to your computer and use it in GitHub Desktop.
Save fisproject/d968318374bc81d7f468613a8205c1cd to your computer and use it in GitHub Desktop.
A Ubuntu initscript for go-simple-server
#!/bin/sh
EXEC=/usr/local/bin/server
PIDFILE=/var/run/go-simple-server.pid
USER=ubuntu
###############
# SysV Init Information
# chkconfig: - 58 74
# description: go-simple-server is the dsmllib API server daemon.
### BEGIN INIT INFO
# Provides: go-simple-server
# Required-Start: $network $local_fs $remote_fs
# Required-Stop: $network $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Should-Start: $syslog $named
# Should-Stop: $syslog $named
# Short-Description: start and stop go-simple-server
# Description: dsmllib API server daemon
### END INIT INFO
case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting go-simple-server..."
start-stop-daemon --start -c ${USER} --quiet --background --exec $EXEC --make-pidfile --pidfile $PIDFILE
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
start-stop-daemon --stop --quiet --pidfile $PIDFILE
while [ -x /proc/${PID} ]
do
echo "Waiting for go-simple-server to shutdown ..."
sleep 1
done
rm $PIDFILE
echo "go-simple-server stopped"
fi
;;
status)
if [ ! -f $PIDFILE ]
then
echo 'go-simple-server is not running'
else
PID=$(cat $PIDFILE)
if [ ! -x /proc/${PID} ]
then
echo 'go-simple-server is not running'
else
echo "go-simple-server is running ($PID)"
fi
fi
;;
restart)
$0 stop
$0 start
;;
*)
echo "Please use start, stop, restart or status as first argument"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment