nginxd 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #!/bin/sh
  2. #
  3. # chkconfig: 2345 55 25
  4. # Description: Nginx init.d script, put in /etc/init.d, chmod +x /etc/init.d/nginx
  5. # For Debian, run: update-rc.d -f nginx defaults
  6. # For CentOS, run: chkconfig --add nginx
  7. #
  8. ### BEGIN INIT INFO
  9. # Provides: nginx
  10. # Required-Start: $all
  11. # Required-Stop: $all
  12. # Default-Start: 2 3 4 5
  13. # Default-Stop: 0 1 6
  14. # Short-Description: nginx init.d script
  15. # Description: OpenResty (aka. ngx_openresty) is a full-fledged web application server by bundling the standard Nginx core, lots of 3rd-party Nginx modules, as well as most of their external dependencies.
  16. ### END INIT INFO
  17. #
  18. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  19. DESC="Nginx Daemon"
  20. NAME=nginx
  21. PREFIX=/usr/local/openresty/nginx
  22. DAEMON=$PREFIX/sbin/$NAME
  23. CONF=$PREFIX/conf/$NAME.conf
  24. PID=/run/nginx.pid
  25. SCRIPT=/etc/init.d/$NAME
  26. if [ ! -x "$DAEMON" ] || [ ! -f "$CONF" ]; then
  27. echo -e "\033[33m $DAEMON has no permission to run. \033[0m"
  28. echo -e "\033[33m Or $CONF doesn't exist. \033[0m"
  29. sleep 1
  30. exit 1
  31. fi
  32. do_start() {
  33. if [ -f $PID ]; then
  34. echo -e "\033[33m $PID already exists. \033[0m"
  35. echo -e "\033[33m $DESC is already running or crashed. \033[0m"
  36. echo -e "\033[32m $DESC Reopening $CONF ... \033[0m"
  37. $DAEMON -s reopen -c $CONF
  38. sleep 1
  39. echo -e "\033[36m $DESC reopened. \033[0m"
  40. else
  41. echo -e "\033[32m $DESC Starting $CONF ... \033[0m"
  42. $DAEMON -c $CONF
  43. sleep 1
  44. echo -e "\033[36m $DESC started. \033[0m"
  45. fi
  46. }
  47. do_stop() {
  48. if [ ! -f $PID ]; then
  49. echo -e "\033[33m $PID doesn't exist. \033[0m"
  50. echo -e "\033[33m $DESC isn't running. \033[0m"
  51. else
  52. echo -e "\033[32m $DESC Stopping $CONF ... \033[0m"
  53. $DAEMON -s stop -c $CONF
  54. sleep 1
  55. echo -e "\033[36m $DESC stopped. \033[0m"
  56. fi
  57. }
  58. do_reload() {
  59. if [ ! -f $PID ]; then
  60. echo -e "\033[33m $PID doesn't exist. \033[0m"
  61. echo -e "\033[33m $DESC isn't running. \033[0m"
  62. echo -e "\033[32m $DESC Starting $CONF ... \033[0m"
  63. $DAEMON -c $CONF
  64. sleep 1
  65. echo -e "\033[36m $DESC started. \033[0m"
  66. else
  67. echo -e "\033[32m $DESC Reloading $CONF ... \033[0m"
  68. $DAEMON -s reload -c $CONF
  69. sleep 1
  70. echo -e "\033[36m $DESC reloaded. \033[0m"
  71. fi
  72. }
  73. do_quit() {
  74. if [ ! -f $PID ]; then
  75. echo -e "\033[33m $PID doesn't exist. \033[0m"
  76. echo -e "\033[33m $DESC isn't running. \033[0m"
  77. else
  78. echo -e "\033[32m $DESC Quitting $CONF ... \033[0m"
  79. $DAEMON -s quit -c $CONF
  80. sleep 1
  81. echo -e "\033[36m $DESC quitted. \033[0m"
  82. fi
  83. }
  84. do_test() {
  85. echo -e "\033[32m $DESC Testing $CONF ... \033[0m"
  86. $DAEMON -t -c $CONF
  87. }
  88. do_info() {
  89. $DAEMON -V
  90. }
  91. case "$1" in
  92. start)
  93. do_start
  94. ;;
  95. stop)
  96. do_stop
  97. ;;
  98. reload)
  99. do_reload
  100. ;;
  101. restart)
  102. do_stop
  103. do_start
  104. ;;
  105. quit)
  106. do_quit
  107. ;;
  108. test)
  109. do_test
  110. ;;
  111. info)
  112. do_info
  113. ;;
  114. *)
  115. echo "Usage: $SCRIPT {start|stop|reload|restart|quit|test|info}"
  116. exit 2
  117. ;;
  118. esac
  119. exit 0