Linux INIT.D scripting templates

Source: Internet
Author: User

#!/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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.