Skip to content

Instantly share code, notes, and snippets.

@yukikaoru
Created October 24, 2018 08:36
Show Gist options
  • Save yukikaoru/d3af74698aa25f6e78e9f3e04d36205b to your computer and use it in GitHub Desktop.
Save yukikaoru/d3af74698aa25f6e78e9f3e04d36205b to your computer and use it in GitHub Desktop.
init.d template
#!/bin/bash
#
# scriptname short desc
# chkconfig: - 80 20
# description: long description
# processname: scriptname
# Source function library.
. /etc/rc.d/init.d/functions
prog=/path/to/prog
name=$(basename $0)
pidfile=/var/run/$name.pid
lockfile=/var/lock/subsys/$name
RETVAL=0
start() {
echo -n "Starting ${name}..."
#cmd
RETVAL=$0
echo
[ $RETVAL = 0 ] && touch $lockfile
return $RETVAL
}
stop() {
echo -n "Stopping ${name}..."
#cmd
RETVAL=$0
echo
[ $RETVAL = 0 ] && rm -f $lockfile $pidfile
return $RETVAL
}
case $1 in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status -p $pidfile $prog
RETVAL=2
;;
esac
exit $RETVAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment