#!/bin/Bash # # # BEGIN INIT INFO # # provides:location_server # Required-Start: $local _fs $remote _fs # Required-Stop: $local _fs $remote _fs # Default-start:2 3 4 5# Default-stop:0 1 6# Short-Description:initscript # Description:thisfileShould is used to construct scripts to be placedinch/etc/init.d. # # # # END Init INFO # # FillinchName of program here . PROG="Location_server"Prog_path="/opt/location_server"# # need, but sometimes helpful (if$PROG residesinch/opt forexample). Prog_args=""Pid_path="/var/run/"start () {if[-E"$PID _path/$PROG. PID"]; Then# # program was running, exit with error. Echo "error! $PROG is currently running!" 1>&2Exit1 Else# # change from/dev/NULLto something like/var/log/$PROGifYou want to save output. $PROG _path/$PROG $PROG _args2>&1>/var/log/$PROG &$pid=`PSAx |grep-I.'Location_server'|sed 's/^\ ([0-9]\{1,\}\). */\1/g'|Head-N1` Echo "$PROG started" Echo$pid >"$PID _path/$PROG. PID" fi} stop () {Echo "begin Stop" if[-E"$PID _path/$PROG. PID"]; Then# # program was running, so stop it PID=`PSAx |grep-I.'Location_server'|sed 's/^\ ([0-9]\{1,\}\). */\1/g'|Head-N1` Kill$pidRM-F"$PID _path/$PROG. PID" Echo "$PROG stopped" Else# # program isn't running, exit with error. Echo "error! $PROG not started!" 1>&2Exit1 fi} # # Check to seeifwe are running as root first. # # Found at http://www.cyberciti.biz/tips/shell-root-user-check-script.htmlif["$ (id-u)"!="0"]; Then Echo "This script must is run as root" 1>&2Exit1 fi Case " $" inchstart) Start Exit0 ;; Stop) Stop exit0 ;; Reload|restart|force-Reload) stop start exit0 ;; **) Echo "Usage: $ {start|stop|reload}" 1>&2Exit1 ;; Esac
Where the PROG variable is the name of the executable program to be run, Prog_path is the directory where the executables are located, Prog_args the parameters of the executing program.