After ubuntu upgrades to 16.04 - systemd set to boot

Ubuntu no longer uses initd to manage the system since 16.04, and uses systemd instead. Like centos, after upgrading to centos7, systemd is used instead of init.d.
However, systemd is not commonly used by the author, and the changes are too big, which is completely different from the previous one.

Setting up startup with systemd 
In order to set up the startup program in /etc/rc.local as before, the following steps are required:

1. Systemd reads the configuration files under /etc/systemd/system by default, and the files in this directory will link to the files under /lib/systemd/system/. Generally, after the system is installed, there will be a rc-local.service file under /lib/systemd/system/, which is the configuration file we need.

Note: Because at startup, Systemdonly /etc/systemd/systemthe configuration files in the directory are executed. This also means that if the modified configuration file is placed in this directory, the effect of overwriting the original configuration can be achieved. 

Link to:

ln -fs /lib/systemd/system/rc-local.service /etc/systemd/system/rc-local.service

Note: Using systemctl enabled rc-local.service can also achieve the same effect,

systemctl is- enabled unit #Display whether a unit service has established a startup link

systemctl enabled unit #为某个unit服务创建启动链接

View the contents of rc-local.service:
cd /etc/systemd/system/

vim rc-local.service


#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

# This unit gets pulled automatically into multi-user.target by
# systemd-rc-local-generator if /etc/rc.local is executable.
[Unit]
Description=/etc/rc.local Compatibility
ConditionFileIsExecutable=/etc/rc.local
After=network.target

[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no

[Install]
WantedBy=multi-user.target
Alias=rc-local.service


2. Create /etc/rc.local file
touch /etc/rc.local

3. Grant executable permission
chmod 755 /etc/rc. local

4. Edit rc.local and add a task that needs to be booted up

#!/bin/bash
echo "test test " > /var/test_boot_up.log

5. Execute reboot to restart the system to verify OK.

Finally, talk about the configuration file (XXXX.service) under /etc/systemd/system/, 
which has three configuration items, [Unit] / [Service] / [Install] 
1) [Unit] block: startup sequence and dependencies relation. 
2) [Service] block: startup behavior, how to start, and startup type. 

3) The [Install] block defines how to install this configuration file, that is, how to start it.


The author's ubuntu version is 17.10, if unsuccessful, use the command

systemctl enable rc-local.service

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325846187&siteId=291194637