Making an RC Script on Linux
-
Often we need to build our own RC scripts which can be managed via the chkconfig command but we don’t know where to start. Here is a blank framework that simply needs to be filled out in order to work. Once completed, just put into /etc/init.d and use “chkconfig -add scriptname” to enable it.
#!/bin/sh # # name This shell script takes care of starting and stopping # the "name" services. # # chkconfig: - 60 20 # description: Fill in description # probe: true # config: If there is a config file RETVAL=0 uid=`id | cut -d\( -f1 | cut -d= -f2` # See how we were called. case "$1" in start) # Start the process # Only root can stop the service [ $uid -ne 0 ] && exit 4 ;; stop) # Stop the process # Only root can stop the service [ $uid -ne 0 ] && exit 4 ;; status) # Check on app ;; restart) $0 stop $0 start ;; *) echo $"Usage: nfs {start|stop|status|restart}" RETVAL=2 ;; esac exit $RETVAL
Originally found on my Linux blog in 2014: http://web.archive.org/web/20140825114908/http://www.scottalanmiller.com/linux/2014/06/27/making-an-rc-script/