How to quickly write a startup script , mainly through the following several
1, logical smoothing
can be in TXT file, have pseudo code way, form system, List order, then add code in a little bit
Determine if the program is running through the PID process file
Set 3 modules (on, off, Reload)
Then use the case statement to invoke the 3 module to implement the startup script function
Restart See the process number changes, reload see if the configuration file is in effect
2, Script body content
[[email protected]]# cat /etc/init.d/nginx#!/bin/bash# chkconfig: 2345 32 62 #按照开机启动模板设定, 32 serial number 62 system level # description: activates/deactivates all network interfaces configured to [ -f /etc/init.d/functions ] && . /etc/init.d/functions #引用系统函数库nginx =/application/nginx/sbin/ Nginxpidfile=/application/nginx/logs/nginx.pidoldboy () { retval=$? if [ $RETVAL -eq 0 ];then action "Nginx is $1 " /bin/true else action " Nginx is $1 " /bin/false fi}# #no .1 definition Startup module start () { if [ -f $Pidfile ];then echo "nginx is running" else $nginx oldboy started fi return $ retval}# #no .2 definition Shutdown module stop () { if [ ! -f $Pidfile ];then echo "Nginx in not running" else $nginx -s stop oldboy stoped fi}# #no .3 Define reload Module reload () { if [ ! -f $Pidfile ];then echo "Cat ' t open $Pidfile ,no such file or directory" else $nginx -s reload oldboy reloaed fi} case "$" in start) Start;; stop) Stop;; reload) Reload;; restart)   &NBsp; stop sleep 2 start;; *) echo "usage: sh $0 {start|stop|reload| restart} " exit 1esacexit $RETVAL
3, put the script under the/etc/init.d/.
3.1 Viewing the service self-launch list
[[email protected] init.d]# chkconfig--list|grep nginx[[email protected] init.d]# chkconfig--list|grep mysqlmysqld 0: Off 1: Off 2: Enable 3: Enable 4: Enable 5: Enable 6: Off
3.2 Writing scripts to/ETC/INIT.D
[Email protected] init.d]# Cd/etc/init.d/[[email protected] init.d]# VI nginx #内容见上面脚本
3.3 Authorization Script x Execute permissions
[[email protected] init.d]# chmod +x nginx [[email protected] init.d]# ll nginx-rwxr-xr-x 1 root root 1177 September 15:45 n Ginx
4. Add Boot from boot
[[email protected] init.d]# chkconfig nginx onservice Nginx does not support Chkconfig # #报错, no Nginx file added to boot from boot [email Protected] rc3.d]# chkconfig--list|grep nginxnginx 0: Off 1: Off 2: Enable 3: Enable 4: Enable 5: Enable 6: Off
4.1 Testing
[Email protected] rc3.d]#/etc/init.d/nginx Startnginx is running
Another, boot-start method, you can put the boot content in the /etc/rc.local file, mainly to use absolute path
650) this.width=650; "src=" https://s4.51cto.com/wyfs02/M02/A6/27/wKioL1nKCdrgHxKuAADIJXOP2sg114.jpg "title=" 1.jpg "alt=" Wkiol1nkcdrghxkuaadijxop2sg114.jpg "/>
This article is from the "funny Brother Notes" blog, be sure to keep this source http://qiuyt.blog.51cto.com/1229789/1968880
2 minutes-implementation of the boot-up nginx boot script (Shell article)