Skip to content

Instantly share code, notes, and snippets.

@mmirolim
Created February 25, 2015 17:14
Show Gist options
  • Select an option

  • Save mmirolim/714ac1b6f9e8b1fc16f5 to your computer and use it in GitHub Desktop.

Select an option

Save mmirolim/714ac1b6f9e8b1fc16f5 to your computer and use it in GitHub Desktop.
start stop daemon example
#! /bin/sh
### BEGIN INIT INFO
# Provides: skeleton
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Example initscript
# Description: This file should be used to construct scripts to be
# placed in /etc/init.d.
### END INIT INFO
# Author: Foo Bar <[email protected]>
#
# Please remove the "Author" lines above and replace them
# with your own name if you copy and modify this script.
# Do NOT "set -e"
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="Description of the service"
NAME=go-ws-daemon
DAEMON=/var/www/go-ws-daemon/$NAME
DAEMON_ARGS="-conf=/var/www/go-ws-daemon/config.toml -views=/var/www/go-ws-daemon/views"
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
# and status_of_proc is working.
. /lib/lsb/init-functions
#
# Function that starts the daemon/service
#
do_start()
{
nohup $DAEMON &
}
#
# Function that stops the daemon/service
#
do_stop()
{
PIDNO=$(cat $PIDFILE)
echo $PIDNO
kill -s 15 $PIDNO
rm -f $PIDFILE
}
#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
#
# If the daemon can reload its configuration without
# restarting (for example, when it is sent a SIGHUP),
# then implement that here.
#
PIDNO=$(cat $PIDFILE)
echo $PIDNO
kill -s 1 $PIDNO
return 0
}
case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
do_start
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
;;
status)
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
;;
restart)
log_daemon_msg "Restarting $DESC" "$NAME"
do_reload
;;
help)
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
exit 3
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment