UbuntuNginx Automatic startup

Source: Internet
Author: User
The update-rc.d command is used to automatically upgrade the SystemV type initialization script, simply put, what is what you want the system to run during boot initialization, if you want to stop the instance when it is shut down or restarted, you can use it to help you set it. First, we need to create an nginx script file under the/etc/init. d/directory. Run vingpattern to enter the following content #! /Bin/sh # Author: ruiding # Modified: Ge

The update-rc.d command is used to automatically upgrade the System V type initialization script, simply put, what is what you want the System to run during boot initialization, if you want to stop the instance when it is shut down or restarted, you can use it to help you set it.

First, create an nginx script file in the/etc/init. d/directory. Run vi nginx to enter the following content:

#! /Bin/sh
# Author: rui ding
# Modified: Geoffrey Grosenbach http://www.linuxidc.com
# Modified: Clement NEDELCU
# Reproduced with express authorization from its contributors
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_start (){
$ DAEMON | echo-n "already running"
}

D_stop (){
$ DAEMON-s quit | echo-n "not running"
}

D_reload (){
$ DAEMON-s reload | echo-n "cocould not reload"
}

Case "$1" in
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 shoshould give
# Nginx daemon some time to perform a graceful stop.
Sleep 2
D_start
Echo "."
;;
*)
Echo "Usage: $ SCRIPTNAME {start | stop | restart | reload}"> & 2
Exit 3
;;
Esac
Exit 0

Enter the following command

[root@example.com ~]# update-rc.d –f nginx defaults

Okay. Check if NGINX is started again.

If you want to cancel boot, you can do this.

update-rc.d -f nginx remove

Additional information:

All the startup scripts are stored in/etc/init. d/. We can start an application in the/etc/init. d/Script Name startup mode. For example, enter the command "/etc/init. d/smb start" to start the smb service. In the RedHat system, you can use service smb start to start a service.

Although/etc/init. the script in the d directory can start and stop various services, but during system boot, init is not directly in/etc/init. d directory to find the startup scripts for each service, but in/etc/rc. d/directory. The directory contains directories that represent different init startup levels, such as rc0.d and rc1.d.

You can run the Runlevel command to check the running level of your system.

# Runlevel N 2 Note: My current system is Level 2

Next, let's take a look at the content contained in these rcx. d directories. The content is full of symbolic links and linked to the scripts in the init directory at the upper level. These symbolic links start with S or K, followed by a number and the service name controlled by the script, such as S10network. When init transits from a low running level to a high running level, it runs all scripts starting with S in the ascending order of numbers. S = start, that is, the services corresponding to the startup script; K = kill, that is, the service corresponding to the script is killed.

Rcx. the symbolic link pointing to the startup script under the d directory is composed of K or S + number + service name, which is very important in the middle, when the system starts, the script starting with "S" is executed progressively according to this number. When the system is down, the script starting with "K" is executed progressively.

How do I customize symbolic links? Startup Script: Because the running level is Level 2, it runs in the/etc/rc. d/rc2.d directory.

# Ln-s/etc/init. d/nginx S99nginx // re-define the script startup sequence of the nginx Service

 

 

 

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.