漂亮蓝影 发表于 2018-11-9 13:37:35

解决“service nginx does not support chkconfig”的问题?

  因为这2天要安装nginx服务器,其nginx没有提供启动脚本,就想自己写一个启动脚本,但是再写完脚本的时候,想使用service启动该服务,
  nginx启动脚本如下:
  #!/bin/bash
  #StartupscriptforthenginxWebServer
  #description:nginxisaWorldWideWebserver.Itisusedtoserve
  #HTMLfilesandCGI.
  #processname:nginx
  #pidfile:/usr/local/nginx/logs/nginx.pid
  #config:/usr/local/nginx/conf/nginx.conf
  PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
  exportPATH
  NGINX_HOME=/usr/local/nginx/sbin
  NGINX_CONF=/usr/local/nginx/conf
  PHP_HOME=/usr/local/php-fcgi/bin
  if[!-f"$NGINX_HOME/nginx"]
  then
  echo"nginxserverstartup:cannotstart"
  exit
  fi
  case"$1"in
  'start')
  $PHP_HOME/spawn-fcgi-a127.0.0.1-p10080-C20-unobody-f$PHP_HOME/php-cgi
  $NGINX_HOME/nginx-c$NGINX_CONF/nginx.conf
  echo"nginxstartsuccessful"
  ;;
  'stop')
  killall-TERMphp-cgi
  killall-TERMnginx
  ;;
  esac
  #chkconfig--addnginx
  servicenginxdoesnotsupportchkconfig
  很是奇怪,后经过查找资料,发现如果想添加脚本用service启动,必须要脚本里面包含这2行:
  #chkconfig:-8515
  #description:nginxisaWorldWideWebserver.Itisusedtoserve
  其他的都不所谓,只是个注意而已!!!
  修改后的nginx启动脚本:
  #!/bin/bash
  #StartupscriptforthenginxWebServer
  #chkconfig:-8515
  #description:nginxisaWorldWideWebserver.Itisusedtoserve
  #HTMLfilesandCGI.
  #processname:nginx
  #pidfile:/usr/local/nginx/logs/nginx.pid
  #config:/usr/local/nginx/conf/nginx.conf
  PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
  exportPATH
  NGINX_HOME=/usr/local/nginx/sbin
  NGINX_CONF=/usr/local/nginx/conf
  PHP_HOME=/usr/local/php-fcgi/bin
  if[!-f"$NGINX_HOME/nginx"]
  then
  echo"nginxserverstartup:cannotstart"
  exit
  fi
  case"$1"in
  'start')
  $PHP_HOME/spawn-fcgi-a127.0.0.1-p10080-C20-unobody-f$PHP_HOME/php-cgi
  $NGINX_HOME/nginx-c$NGINX_CONF/nginx.conf
  echo"nginxstartsuccessful"
  ;;
  'stop')
  killall-TERMphp-cgi
  killall-TERMnginx
  ;;
  esac
  #chkconfig--addnginx
  ok,没有错误提示,说明添加成功!启动下看看,
  #servicenginxstop
  /sbin/service:line68:18616Terminatedenv-iLANG="$LANG"PATH="$PATH"TERM="$TERM""${SERVICEDIR}/${SERVICE}"${OPTIONS}
  #servicenginxstart
  spawn-fcgi.c.190:childspawnedsuccessfully:PID:18624
  nginxstartsuccessful
  大功告成!

页: [1]
查看完整版本: 解决“service nginx does not support chkconfig”的问题?