[Linux problem] Solve the problem that the rc.local file does not exist (Ubuntu 18.04)

        After the ubuntu16.04 version, the initd management system is no longer used, and systemd is used instead.

Solution:
Step 1: Write rc-local.service file.

        The default service files are stored in the /etc/systemd/system directory, which is a bit like a service configuration file. Note that there is also an rc-local.service under /lib/systemd/system, which can be modified by borrowing this template, or written from scratch.

sudo vim /etc/systemd/system/rc-local.service
[Unit]
 Description=/etc/rc.local Compatibility
 ConditionPathExists=/etc/rc.local
[Service]
 Type=forking
 ExecStart=/etc/rc.local start
 TimeoutSec=0
 StandardOutput=tty
 RemainAfterExit=yes
 SysVStartPriority=99
[Install]
 WantedBy=multi-user.target

        The Unit field mainly describes the startup sequence and dependencies of the service, the Service field mainly describes how to start it, and the Install field describes how to install the service.

Step 2: Activate rc-local.service.

sudo systemctl enable rc-local.service

Step 3: Manually create  /etc/rc.localand grant execution permission.

        The ubuntu 18.04 system has removed the /etc/rc.local file by default, so we need to manually create one and write the commands that need to be executed at boot into the file.  

sudo vim /etc/rc.local
#!/bin/bash
# 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.

# 下面填入开机启动的命令
# ......

exit 0
sudo chmod +x /etc/rc.local

 Step 4: Start the service and check its status.

sudo systemctl start rc-local.service
sudo systemctl status rc-local.service

 

Step 5: reboot to restart verification.

Guess you like

Origin blog.csdn.net/weixin_48896613/article/details/127208376