nginx linux 开机自动启动脚本,centos6 nginx开机启动脚本练习

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

usage(){

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

esac

exit $RETVAL

思路

centos6开机作为启动项时默认会传值start|stop|restart|值

需要注意nginx.pid的文件,随着启动进程号的出现而出现

首先把写好的脚本cp nginx.sh /etc/init.d/nginx

chmod +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 31

init.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 nginx

chkconfig nginx on/off

自启动的机制就是 server 服务 start

所以加入自启动后系统会自动给脚本传start参数

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值