centos6 nginx开机启动脚本练习

95次阅读
没有评论

共计 1359 个字符,预计需要花费 4 分钟才能阅读完成。

#!/bin/bash
# chkconfig: 2345 32 62 
# description: nginx is a http server[-f /etc/init.d/functions] && . /etc/init.d/functions
pidfile=/usr/local/nginx/logs/nginx.pid
nginx=/usr/local/nginx/sbin/nginxusage(){ 
 RETVAL=$?
 if [$RETVAL -eq 0];then
 action "nginx is $1" /bin/true
 else
 action "nginx is $1" /bin/false
 fi
}
Start_nginx(){if [ -f $pidfile]; then
 echo "nginx is runing"
 else
 $nginx start
 RETVAL=$?
 usage STARTED
 fi
 return $RETVAL
}Stop_nginx(){if [ -f $pidfile]; then
 $nginx -s stop
 usage STOPED
 else
 ection "nginx is spoped" /bin/false
 fi
 return $RETVAL
}
Reload_nginx(){if [ -f $pidfile]; then
 $nginx -s reload
 usage RELOAD
 else
 action "nginx is stop, please start nginx!" /bin/false
 fi
 return $RETVAL
}case "$1" in
 start)
 Start_nginx
 RETVAL=$?
 ;;
 stop)
 Stop_nginx
 RETVAL=$?
 ;;
 restart)
 Stop_nginx
 sleep 2
 Start_nginx
 RETVAL=$?
 ;;
 reload)
 Reload_nginx
 RETVAL=$?
 ;;
 *)
 echo "usage:$0 {start|stop|reload|restart}"
 exit 1
esacexit $RETVAL

思路 centos6 开机作为启动项时默认会传值 start|stop|restart| 值 需要注意 nginx.pid 的文件, 随着启动进程号的出现而出现 首先把写好的脚本 cp nginx.sh /etc/init.d/nginxchmod +x /etc/init.d/nginx脚本开始加上启动顺序具体还要了解下基础# chkconfig: 2345 10 90
# description: nginx is a http server需要了解基础 contos 系统启动 nit.d ll /etc/rc.d/rc3.d |grep 31init.d ll /etc/rc.d/rc3.d |grep 32➜  init.d ll /etc/rc.d/rc3.d |grep 61➜  init.d ll /etc/rc.d/rc3.d |grep 62 然后把脚本启动修改为# chkconfig: 2345 31 62
# description: nginx is a http server注意这是 centos6 的使用方法和 7 有不同之处➜ init.d chkconfig –add nginx
➜ init.d chkconfig –list nginxchkconfig nginx on/off自启动的机制就是 server 服务 start所以加入自启动后系统会自动给脚本传 start 参数

正文完
 0
yx
版权声明:本站原创文章,由 yx 于2018-05-04发表,共计1359字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)
验证码