Bricklayer nginx added to system service

http://blog.csdn.net/zhouzme/article/details/19576855



Tip: do not remove the comment at the top, otherwise you cannot register as a system service,

About: chkconfig: 2345 65 37

Online search summarizes the following meaning:

  • 2345 system environment for starting the service
  • 65 is the priority of loading
  • 37 is the priority of shutdown

The values of 65 and 37 can't be the same or conflict with the values of other services. I haven't encountered such problems. If you have any problems, please modify your own configuration


New file:

  1. # vi /etc/init.d/nginx  

Input:

  1. #!/bin/sh  
  2. # Comments to support chkconfig on RedHat Linux  
  3. # chkconfig: 2345 65 37  
  4. # description: A nginx daemon.  
  5.                                                  
  6. set -e  
  7. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin  
  8. DESC="nginx daemon"  
  9. NAME=nginx  
  10. DAEMON=/usr/local/nginx/sbin/$NAME  
  11. SCRIPTNAME=/etc/init.d/$NAME  
  12.                                                  
  13. # If the daemon file is not found, terminate the script.  
  14. test -x $DAEMON || exit 0  
  15.                                                  
  16. d_test() {  
  17.     $DAEMON -t  
  18. }  
  19. d_start() {  
  20.     $DAEMON || echo -n " already running"  
  21. }  
  22. d_stop() {  
  23.     $DAEMON -s quit || echo -n " not running"  
  24. }  
  25. d_reload() {  
  26.     $DAEMON -s reload || echo -n " could not reload"  
  27. }  
  28.                                                  
  29. case "$1" in  
  30.     test)  
  31.       d_test  
  32.       echo "."  
  33.       ;;  
  34.     start)  
  35.       echo -n "Starting $DESC: $NAME"  
  36.       d_start  
  37.       echo "."  
  38.       ;;  
  39.     stop)  
  40.       echo -n "Stopping $DESC: $NAME"  
  41.       d_stop  
  42.       echo "."  
  43.       ;;  
  44.     reload)  
  45.       echo -n "Reloading $DESC configuration..."  
  46.       d_reload  
  47.       echo "reloaded."  
  48.       ;;  
  49.     restart)  
  50.       echo -n "Restarting $DESC: $NAME"  
  51.       d_stop  
  52.       # Sleep for two seconds before starting again, this should give the  
  53.       # Nginx daemon some time to perform a graceful stop.  
  54.       sleep 2  
  55.       d_start  
  56.       echo "."  
  57.       ;;  
  58.     *)  
  59.       echo "Usage: $SCRIPTNAME {test|start|stop|restart|reload}" >&2  
  60.       exit 3  
  61.       ;;  
  62. esac  
  63.                                                  
  64. exit $?  

register nginx Services:

  1. chmod +x /etc/init.d/nginx  
  2. chkconfig --add nginx  
  3. chkconfig --level 2345 nginx on  
  4. chkconfig --list nginx  

Related nginx commands:

Detect nginx configuration

  1. # service nginx test  

start-up

  1. # service nginx start  

Close

  1. # service nginx stop  

restart

  1. # service nginx restart  

Overload configuration

  1. # service nginx reload  


Tags: Nginx Linux

Posted on Sun, 03 May 2020 21:44:50 -0700 by mw-dnb