Ubuntu 16.04 Setup rc.local boot Command/script method (manage Ubuntu boot program/service via UPDATE-RC.D)

Source: Internet
Author: User
Tags memcached

Note: The user initiated in the Rc.local script defaults to the root permission.

One, rc.local script

The rc.local script is a script that will be executed automatically after Ubuntu is powered on, and we can add command-line commands to the script. The script is located under the/etc/path and requires root privileges to be modified.

The script is in the following format:

#!/bin/sh-e# # RC. Local End  on success or any other   on error.## in order to enable or disable this script justchange the execution # bits.## by default this Script does nothing.  Exit 0

Note: Be sure to add the command before exit 0. You can write the command directly or execute the shell script file sh.

Second, on the rc.local inside when the problem does not start:

1, you can first increase the log output function, to see why this script does not start the reason, this is the Memcached startup sample file:

#!/bin/sh-e# # RC.Local# # This script was executed at theEndof each multiuser runlevel.# make sure that the script would "exit 0" onsuccess or any other# value onerror.##In order to enable or disable this script just change the execution# bits.## By default this script does nothing. #logexec 2>/tmp/rc.local.log # send stderr from rc.local to a log file exec 1>&2 # s End stdout to the same log file Set-x # tell sh to display commands before execution /c5>#Memcached/usr/local/memcache/bin/memcached-p 11211- M 64m-d-u root Exit0

2, rc.local file head/bin/sh modified to/bin/bash

3, if is the execution sh file, then to give the Execute permission sudo chmod +x xxx.sh, and then starts to add the sudo sh xxx.sh

Third, UPDATE-RC.D increase boot service

Add a boot script to Ubuntu, as follows:

1. Create a new script file new_service.sh

#!/bin/bashcommand  content  exit 0

2. Set permissions

sudo chmod 755 new_service. SH#+x new_service.sh

3. Place the script in the startup directory

sudo mv new_service.sh/etc/init.d/

4. Add script to startup script

Execute the following command, where 90 indicates a priority, and the higher it is, the more late the execution

cd /etc/init.d/sudo update-rc. D new_service.sh Defaults 90

5, remove Ubuntu boot script

sudo update-rc.d-f new_service.sh Remove

6, through the sysv-rc-conf to manage the boot level of the above start-up service, or boot does not start

sudo sysv-rc-conf

7. Detailed parameters of UPDATE-RC.D

Use update-RC. The D command needs to specify the script name and some parameters, and it looks like this (requires root privileges):

UPDATE-RC.D [-n] [-f] <basename> REMOVEUPDATE-RC. D [-n] <basename> DEFAULTSUPDATE-RC. D [ -N] <basename> disable|enable [s|2|3|4|5]update-rcstart|stop <NN> <runlevels>   not really-f: force

which

  • Disable| Enable: represents the script still in /etc/init. D , and set whether the current state is started manually or automatically.
  • start| means script is also /etc/< Span class= "PLN" >init. , Power on, and set whether the current state starts or stops running. (Can be configured to start running or not after enabling)
  • nn:90 greater than 8080 The corresponding script starts first or stops first)
  • runlevels:

Instance:

(1), add a new startup script Sample_init_script, and specify the default boot order, the default run level (remember what you said earlier, first of all to have the actual file exists in /etc/init . d, even if file /etc/init. D/sample_init_script does not exist, the command will not execute):

UPDATE-RC.D Sample_init_script Defaults

The previous command is equivalent to (the middle is a period symbol):

Start 20 2 3 4 5. Stop 20 0 1 6

(2), install a startup script Sample_init_script, specify the default run level, but the boot order is :

UPDATE-RC.D Sample_init_script Defaults 50

(3), install two startup scripts a,b, let A start before B, and then stop at b :

UPDATE-RC.D Aupdate-rc. D B 20 30

(4), delete a startup script Sample_init_script, if the script does not exist, skip directly:

Update-rc.d-f Sample_init_script Remove

What this command actually does is one by one delete all located /etc/RcX. the D directory points to /etc/init. D in sample_init_script link (there may be multiple linked files),update-RC. D simply simplifies this step.

(5) Disable Apache/MySQL related components from starting up:

UPDATE-RC. d-f apache2 removeupdate-rc. d-f MySQL Remove

8. Start-Stop status of the service

#startsudo service xxx stopsudo service xxx restart

9. View full list of services

sudo service--status-all

Reference:

Http://www.jamescoyle.net/cheat-sheets/791-update-rc-d-cheat-sheet (view full list of services)

http://blog.csdn.net/typ2004/article/details/38712887

http://blog.csdn.net/shb_derek1/article/details/8489112

Http://blog.sina.com.cn/s/blog_79159ef50100z1ax.html

Http://www.linuxidc.com/Linux/2013-01/77553p2.htm

Http://www.jb51.net/article/100413.htm

http://blog.csdn.net/yplee_8/article/details/50342563

http://blog.163.com/[email protected]/blog/static/66693350201731211940840/

Reasons why the Rc.local does not start:

http://fantaxy025025.iteye.com/blog/2097862

Http://www.linuxidc.com/Linux/2016-12/138665.htm

http://blog.csdn.net/sea_snow/article/details/51051289

http://blog.csdn.net/benbenxiongyuan/article/details/58597036

Http://www.cnblogs.com/liulanghe/p/3376380.html

http://blog.csdn.net/zhe_d/article/details/50312967

Ubuntu 16.04 Setup rc.local boot Command/script method (manage Ubuntu boot program/service via UPDATE-RC.D)

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.