Last active
June 3, 2019 10:59
-
-
Save fisproject/65a7929ba5ff0c928c17d44ad3814757 to your computer and use it in GitHub Desktop.
A initscript for go-simple-server using nohup(1)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
EXEC=/usr/local/bin/server | |
PIDFILE=/var/run/go-simple-server.pid | |
############### | |
# 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..." | |
nohup $EXEC & | |
echo $! > $PIDFILE | |
fi | |
;; | |
stop) | |
if [ ! -f $PIDFILE ] | |
then | |
echo "$PIDFILE does not exist, process is not running" | |
else | |
PID=$(cat $PIDFILE) | |
echo "Stopping ..." | |
kill -TERM $PID | |
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