Skip to content

Instantly share code, notes, and snippets.

@fisproject
Last active June 3, 2019 10:58
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/4796610dbea061d2b6d9a69a5c5639ae to your computer and use it in GitHub Desktop.
Save fisproject/4796610dbea061d2b6d9a69a5c5639ae to your computer and use it in GitHub Desktop.
A CentOS 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
# Source function library.
. /etc/init.d/functions
case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting go-simple-server..."
daemon --pidfile=${PIDFILE} --user=${USER} ${EXEC}
echo $(pgrep server) > $PIDFILE
echo
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
killproc -p $PIDFILE
while [ -x /proc/$PID ]
do
echo "Waiting for go-simple-server to shutdown ..."
sleep 1
done
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