Get the App
SLTechnology News&Howtos  ›  Servers  › 

Detailed explanation of an example of adding nginx system Services to CentOS6.3

Shulou Source: shulou.com Published: 2022-06-02 04:43:55 09月26日 Update

Detailed explanation of an example of adding nginx system Services to CentOS6.3

Foreword:

Today, the virtual machine is equipped with a server to organize this nginx service.

Pay attention to the short bar symbol to see if there is any garbled code after it is copied. I encountered this problem before, and it took me a long time to find out.

Tip: don't remove the comments at the top or you can't register as a system service.

About: chkconfig: 2345 65 37

The online search summed up the following meaning:

2345 for the system environment 65 that starts the service, the priority level 37 for loading is the priority level for shutdown.

The values of these two locations cannot be the same, nor can they conflict with the values of other services. I have never encountered such a problem. If you find any problems, please modify your own configuration.

Create a new file:

# vi / etc/init.d/nginx

Enter the content:

#! / bin/sh # Comments to support chkconfig on RedHat Linux # chkconfig: 2345 65 37 # description: A nginx daemon. Set-e PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DESC= "nginx daemon" NAME=nginx DAEMON=/usr/local/nginx/sbin/$NAME SCRIPTNAME=/etc/init.d/$NAME # If the daemon file is not found, terminate the script. Test-x $DAEMON | | exit 0 d_test () {$DAEMON-t} d_start () {$DAEMON | | echo-n "already running"} d_stop () {$DAEMON-s quit | | echo-n "not running"} d_reload () {$DAEMON-s reload | echo-n "could not reload"} case "$1" in test) d_test echo. " Start) echo-n "Starting $DESC: $NAME" d_start echo ".;; stop) echo-n" Stopping $DESC: $NAME "d_stop echo".;; reload) echo-n "Reloading $DESC configuration..." D_reload echo "reloaded."; restart) echo-n "Restarting $DESC: $NAME" d_stop # Sleep for two seconds before starting again, this should give the # Nginx daemon some time to perform a graceful stop. Sleep 2 d_start echo "."; *) echo "Usage: $SCRIPTNAME {test | start | stop | restart | reload}" > & 2 exit 3;; esac exit $?

Register for the nginx service:

Chmod + x / etc/init.d/nginx chkconfig-add nginx chkconfig-level 2345 nginx on chkconfig-list nginx

Related nginx commands:

Detect nginx configuration

# service nginx test

Start

# service nginx start

Close

# service nginx stop

Restart

# service nginx restart

Overload configuration

# service nginx reload

If you have any questions, please leave a message or go to the community to exchange and discuss, thank you for reading, hope to help you, thank you for your support!

Tags: Service system problem configuration value level instance same depressed two garbled location content preface command meaning file server horizontal bar comment Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Microsoft Docker Shulou Tech Info Huawei