Nginx startup script/Restart script

Source: Internet
Author: User

The first step

Run command to close Nginx first

[Plain]View PlainCopy
    1. sudo kill ' cat/usr/local/nginx/logs/nginx.pid '


Step Two

[HTML]View PlainCopy
    1. Vi/etc/init.d/nginx


Enter the following content

[Plain]View PlainCopy
  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 are 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 "$" in
  64. Start
  65. Rh_status_q && Exit 0
  66. $
  67. ;;
  68. Stop
  69. Rh_status_q | | Exit 0
  70. $
  71. ;;
  72. Restart|configtest)
  73. $
  74. ;;
  75. Reload
  76. Rh_status_q | | Exit 7
  77. $
  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: $ {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
  90. Exit 2
  91. Esac

Save exit

Step Three

[HTML]View PlainCopy
    1. chmod +x/etc/init.d/nginx


Fourth Step

[Plain]View PlainCopy
    1. /sbin/chkconfig Nginx on

Check it out.

[Plain]View PlainCopy
    1. Sudo/sbin/chkconfig--list Nginx
    2. Nginx 0:off 1:off 2:on 3:on 4:on 5:on 6:off

Complete!

After that, you can use the following command.

[Plain]View PlainCopy < param name= "wmode" value= "Transparent" >
      1. Service Nginx Start
      2. Service Nginx Stop
      3. Service Nginx Restart
      4. Service Nginx Reload
      5. /etc/init.d/nginx start
      6. /etc/init.d/nginx stop
      7. /etc/init.d/nginx restart
      8. /etc/init.d/nginx Reload

Nginx startup script/Restart script

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.