Linux boot autorun / etc / RC Local and / etc / init d

**

1. /etc/rc.local

**

This is the user-defined startup program. Write the program that needs to be started automatically in this script. In the last stage of linux startup, the system will execute and store it in RC Commands in local.

The script is executed after the system initialization level script runs, so you can safely add the script you want to execute after the system starts. The common situation is that you can add nfs mount / Mount script to it. In addition, you can also add some script commands for debugging. For example, I have encountered this situation: the samba service always fails to run normally, and the inspection found that Samba should be started and executed during system startup, that is, the samba daemon configuration ensures that this function should be executed correctly. In this case, I don't bother to spend a lot of time to find out why. I just need to simply check in / etc / RC Add this line to the local script:

      /etc/init.d/samba start

This successfully solves the problem of samba service exception.

Another way to write it is in / etc / RC Add this line to the local script:

downey@ubuntu:~$ cat /etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
./usr/bin/diodon &
exit 0

Add & after the shell executes the command to make the application run in the background, RC Local is also a script. The main process must be able to return when running this script. If some dead cycles or other tasks that cannot be returned are executed in this script, the whole system is likely to be stuck here and cannot be started. Therefore, the user program running here must be able to return or use some processes running in the background.

After the above addition, use the following command at the next restart:

downey@ubuntu:~$ ps -ef |grep "diodon"
downey     2097   1880  0 22:53 ?        00:00:04 diodon
downey     2937   2842  0 23:27 pts/2    00:00:00 grep --color=auto diodon  

**

2. About / etc / init d

**
init. The D directory contains start and stop scripts for many system services. It controls all transactions from acpid to X11 common.

/etc/init.d # ls
ls
adbd                forwarder           odhcpd              telnet
boot                fstab               prod_init           umount
cm.init             led                 prod_usb_init       upnpd
cron                lighttpd            rdp_init            usb_init
cwlan               log                 sdcard_mount        usr_data_sync
dnsmasq             lte-telephony       services.init       wlan-del-mac
done                lte-telephony-prod  sysctl              zram
dropbear            mrvl_init           sysfixtime
enable_autosleep    mrvl_init_aquila    sysntpd
firewall            network             system

When you look at the / etc directory, you will find many rc# Directories in the form of D (here # represents a specified initialization level, ranging from 0 to 6). Under these directories, there are many scripts to control the process. These scripts either start with "K" or start with "s" start. Scripts starting with K run before scripts starting with S. Where these scripts are placed will determine when they start running. Between these directories, system services work together, just like machines in good health. However, sometimes you want to start or kill a process cleanly without using the kill or kill commands. This is / etc / init D can come in handy!

/etc/init.d # cd ../rc.d
cd ../rc.d
/etc/rc.d # ls
ls
K50dropbear          S10boot              S35odhcpd
K85odhcpd            S10cwlan             S40fstab
K89log               S10dnsmasq           S42services.init
K89prod_init         S10network           S50cron
K89rdp_init          S11cm.init           S50dropbear
K90forwarder         S11forwarder         S50lighttpd
K90network           S11rdp_init          S50sdcard_mount
K90sysfixtime        S11sysctl            S50telnet
K91sdcard_mount      S11system            S65upnpd
K97lte-telephony     S11zram              S80adbd
K98boot              S12firewall          S95done
K99adbd              S12log               S96led
K99umount            S12lte-telephony     S99enable_autosleep
S00sysfixtime        S13prod_init

To be able to use init D directory, you need root permission or sudo permission. Each script will be run as a command. The structure of the command is roughly as follows:

 /etc/init.d/command option

 comand It is the actual running command, and the options can be as follows:
 start
 stop
 reload
 restart
 force-reload

For example:

 In most cases, you will use start,stop,restart Options. For example, if you want to turn off the network, you can use the following command:

     /etc/init.d/networking stop

    As another example, you change the network settings and need to restart the network. You can use the following command:

    /etc/init.d/networking restart

init. The common initialization scripts in the D directory are:

networking
samba
apache2
ftpd
sshd
dovecot
mysql
Of course, you may have more commonly used scripts, depending on what linux operating system you have installed

Keywords: Linux Operation & Maintenance server

Added by cupboy on Tue, 14 Dec 2021 11:55:51 +0200