始创于2000年 股票代码:831685
咨询热线:0371-60135900 注册有礼 登录
  • 挂牌上市企业
  • 60秒人工响应
  • 99.99%连通率
  • 7*24h人工
  • 故障100倍补偿
您的位置: 网站首页 > 帮助中心>文章内容

把nginx加入到系统服务,利用chkconfig控制

发布时间:  2012/8/2 18:06:22

 独自等待
  1、编写脚本,名为nginx
  #!/bin/sh
  #
  # nginx - this script starts and stops the nginx daemon
  #
  # chkconfig: - 85 15
  # description: Nginx is an HTTP(S) server, HTTP(S) reverse \
  # proxy and IMAP/POP3 proxy server
  # processname: nginx
  # config: /etc/nginx/nginx.conf
  # config: /etc/sysconfig/nginx
  # pidfile: /var/run/nginx.pid
  # Source function library.
  . /etc/rc.d/init.d/functions
  # Source networking configuration.
  . /etc/sysconfig/network
  # Check that networking is up.
  [ "$NETWORKING" = "no" ] && exit 0
  nginx="/usr/local/nginx/sbin/nginx"
  prog=$(basename $nginx)
  NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
  [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
  lockfile=/var/lock/subsys/nginx
  start() {
  [ -x $nginx ] || exit 5
  [ -f $NGINX_CONF_FILE ] || exit 6
  echo -n $"Starting $prog: "
  daemon $nginx -c $NGINX_CONF_FILE
  retval=$?
  echo
  [ $retval -eq 0 ] && touch $lockfile
  return $retval
  }
  stop() {
  echo -n $"Stopping $prog: "
  killproc $prog -QUIT
  retval=$?
  echo
  [ $retval -eq 0 ] && rm -f $lockfile
  return $retval
  killall -9 nginx
  }
  restart() {
  configtest || return $?
  stop
  sleep 1
  start
  }
  reload() {
  configtest || return $?
  echo -n $"Reloading $prog: "
  killproc $nginx -HUP
  RETVAL=$?
  echo
  }
  force_reload() {
  restart
  }
  configtest() {
  $nginx -t -c $NGINX_CONF_FILE
  }
  rh_status() {
  status $prog
  }
  rh_status_q() {
  rh_status >/dev/null 2>&1
  }
  case "$1" in
  start)
  rh_status_q && exit 0
  $1
  ;;
  stop)
  rh_status_q || exit 0
  $1
  ;;
  restart|configtest)
  $1
  ;;
  reload)
  rh_status_q || exit 7
  $1
  ;;
  force-reload)
  force_reload
  ;;
  status)
  rh_status
  ;;
  condrestart|try-restart)
  rh_status_q || exit 0
  ;;
  *)
  echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
  exit 2
  esac
  2、加入chkconfig
  [root@example ~]# cp nginx /etc/init.d/
  [root@example ~]# chmod 755 /etc/init.d/nginx
  [root@example ~]# chkconfig --add nginx
  3、nginx启动、停止、无间断服务重启
  [root@example ~]# service nginx start
  [root@example ~]# service nginx stop
  [root@example ~]# service nginx reload

亿恩科技地址(ADD):郑州市黄河路129号天一大厦608室 邮编(ZIP):450008 传真(FAX):0371-60123888
   联系:亿恩小凡
   QQ:89317007
   电话:0371-63322206


本文出自:亿恩科技【www.enkj.com】

服务器租用/服务器托管中国五强!虚拟主机域名注册顶级提供商!15年品质保障!--亿恩科技[ENKJ.COM]

  • 您可能在找
  • 亿恩北京公司:
  • 经营性ICP/ISP证:京B2-20150015
  • 亿恩郑州公司:
  • 经营性ICP/ISP/IDC证:豫B1.B2-20060070
  • 亿恩南昌公司:
  • 经营性ICP/ISP证:赣B2-20080012
  • 服务器/云主机 24小时售后服务电话:0371-60135900
  • 虚拟主机/智能建站 24小时售后服务电话:0371-60135900
  • 专注服务器托管17年
    扫扫关注-微信公众号
    0371-60135900
    Copyright© 1999-2019 ENKJ All Rights Reserved 亿恩科技 版权所有  地址:郑州市高新区翠竹街1号总部企业基地亿恩大厦  法律顾问:河南亚太人律师事务所郝建锋、杜慧月律师   京公网安备41019702002023号
      0
     
     
     
     

    0371-60135900
    7*24小时客服服务热线