使用chkconfig 将nginx加入自启动

记录下使用chkconfig将nginx加入自启动的过程
一.在 /etc/init.d中编写nginx文件

  1	#!/bin/bash
  2 # nginx Startup script for the Nginx HTTP Server
  3 # it is v.0.0.2 version.
  4 # chkconfig: - 85 15
  5 # description: Nginx is a high-performance web and proxy server.
  6 #              It has a lot of features, but it's not for everyone.
  7 # processname: nginx
  8 # pidfile: /var/run/nginx.pid
  9 # config: /usr/local/nginx/conf/nginx.conf
 10 nginxd=/usr/local/nginx/sbin/nginx
 11 nginx_config=/usr/local/nginx/conf/nginx.conf
 12 nginx_pid=/usr/local/nginx/logs/nginx.pid
 13 RETVAL=0
 14 prog="nginx"
 15 # Source function library.
 16 . /etc/rc.d/init.d/functions
 17 # Source networking configuration.
 18 . /etc/sysconfig/network
 19 # Check that networking is up.
 20 [ ${NETWORKING} = "no" ] && exit 0
 21 [ -x $nginxd ] || exit 0
22 
 23 # Start nginx daemons functions.
 24 start() {
 25 if [ -e $nginx_pid ];then
 26    echo "nginx already running...."
 27       exit 1
 28       fi
 29          echo -n $"Starting $prog: "
 30             daemon $nginxd -c ${nginx_config}
 31                RETVAL=$?
 32                   echo
 33                      [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
 34                         return $RETVAL
 35 }
 36 
 37 # Stop nginx daemons functions.
 38 stop() {
 39         echo -n $"Stopping $prog: "
 40                 killproc $nginxd
 41         		RETVAL=$?
 42							echo
 43                                         [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
 44 }
 45 
 46 
 47 # reload nginx service functions.
 48 reload() {
 49     echo -n $"Reloading $prog: "
 50         #kill -HUP `cat ${nginx_pid}`
 51             killproc $nginxd -HUP
 52                 RETVAL=$?
 53                     echo
 54 }
 55 
 56 
 57 
 58 
 59 # See how we were called.
 60 case "$1" in
 61 start)
 62     start
 63     ;;
 64 stop)
 65     stop
 66     ;;
 67 reload)
 68     reload
 69     ;;
 70 restart)
 71     stop
 72     start
 73     ;;
 74 status)
 75     status $prog
 76     RETVAL=$?
 77     ;;
 78 *)
 79     echo $"Usage: $prog {start|stop|restart|reload|status|help}"
 80     exit 1
 81 esac
 82 exit $RETVAL


其中
1)nginxd是nginx启动程序的路径
2)nginx_config是nginx的配置文件存放的路径
3)nginx_pid是配置文件中 pid文件存放的路径

二.给nginx文件赋权

chmod 755 nginx

三.chkconfig操作

# 
chkconfig --add nginx

chkconfig nginx on

在这里插入图片描述
如图所示,就为配置成功

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值