服务器维护,服务器代维,安全设置,漏洞扫描,入侵检测服务

运维之家

 找回密码
 注册
搜索
查看: 3655|回复: 0

Nginx 启动脚本/重启脚本

[复制链接]
dirtysea 发表于 2010-9-3 13:30:25 | 显示全部楼层 |阅读模式
Nginx 启动脚本/重启脚本

  1. #!/bin/sh
  2. #
  3. # nginx - this script starts and stops the nginx daemin
  4. #
  5. # chkconfig: - 85 15
  6. # description: Nginx is an HTTP(S) server, HTTP(S) reverse \
  7. # proxy and IMAP/POP3 proxy server
  8. # processname: nginx
  9. # config: /usr/local/nginx/conf/nginx.conf
  10. # pidfile: /usr/local/nginx/logs/nginx.pid
  11. # Source function library.
  12. . /etc/rc.d/init.d/functions
  13. # Source networking configuration.
  14. . /etc/sysconfig/network
  15. # Check that networking is up.
  16. [ "$NETWORKING" = "no" ] && exit 0
  17. nginx="/usr/local/nginx/sbin/nginx"
  18. prog=$(basename $nginx)
  19. NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
  20. lockfile=/var/lock/subsys/nginx
  21. start() {
  22. [ -x $nginx ] || exit 5
  23. [ -f $NGINX_CONF_FILE ] || exit 6
  24. echo -n $"Starting $prog: "
  25. daemon $nginx -c $NGINX_CONF_FILE
  26. retval=$?
  27. echo
  28. [ $retval -eq 0 ] && touch $lockfile
  29. return $retval
  30. }
  31. stop() {
  32. echo -n $"Stopping $prog: "
  33. killproc $prog -QUIT
  34. retval=$?
  35. echo
  36. [ $retval -eq 0 ] && rm -f $lockfile
  37. return $retval
  38. }
  39. restart() {
  40. configtest || return $?
  41. stop
  42. start
  43. }
  44. reload() {
  45. configtest || return $?
  46. echo -n $"Reloading $prog: "
  47. killproc $nginx -HUP
  48. RETVAL=$?
  49. echo
  50. }
  51. force_reload() {
  52. restart
  53. }
  54. configtest() {
  55. $nginx -t -c $NGINX_CONF_FILE
  56. }
  57. rh_status() {
  58. status $prog
  59. }
  60. rh_status_q() {
  61. rh_status >/dev/null 2>&1
  62. }
  63. case "$1" in
  64. start)
  65. rh_status_q && exit 0
  66. $1
  67. ;;
  68. stop)
  69. rh_status_q || exit 0
  70. $1
  71. ;;
  72. restart|configtest)
  73. $1
  74. ;;
  75. reload)
  76. rh_status_q || exit 7
  77. $1
  78. ;;
  79. force-reload)
  80. force_reload
  81. ;;
  82. status)
  83. rh_status
  84. ;;
  85. condrestart|try-restart)
  86. rh_status_q || exit 0
  87. ;;
  88. *)
  89. echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
  90. exit 2
  91. esac
复制代码




chmod +x /etc/init.d/nginx


/sbin/chkconfig nginx on

/sbin/chkconfig --list nginx
nginx           0:off   1:off   2:on    3:on    4:on    5:on    6:off

完成之后,就可以使用以下命令了
service nginx start
service nginx stop
service nginx restart
service nginx reload
/etc/init.d/nginx start
/etc/init.d/nginx stop
/etc/init.d/nginx restart
/etc/init.d/nginx reload
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|小黑屋|手机版|Archiver|运维之家

GMT+8, 2022-1-25 13:23 , Processed in 0.085119 second(s), 14 queries .

Powered by Dirtysea

© 2008-2020 Dirtysea.com.

快速回复 返回顶部 返回列表