本文是該文的整理版。redis
Ubuntu18.04再也不使用initd管理系統,改用systemd。爲了像之前同樣,在/etc/rc.local中設置開機啓動程序,須要如下幾步:bash
一、systemd默認讀取/etc/systemd/system下的配置文件,該目錄下的文件會連接/lib/systemd/system/下的文件。通常系統安裝完/lib/systemd/system/下會有rc-local.service文件,即咱們須要的配置文件。spa
建立軟連接:.net
ln -fs /lib/systemd/system/rc-local.service /etc/systemd/system/rc-local.service
cd /etc/systemd/system/ cat rc-local.service
rc-local.service內容blog
# SPDX-License-Identifier: LGPL-2.1+
#
# 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
Documentation=man:systemd-rc-local-generator(8)
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
區塊解釋:ip
[Unit]:啓動順序與依賴關係。get
[Service]:啓動行爲,如何啓動,啓動類型。generator
[Install] :定義如何安裝這個配置文件,即怎樣作到開機啓動。it
二、建立/etc/rc.local文件,賦可執行權限io
touch /etc/rc.local
chmod 755 /etc/rc.local
三、編輯/etc/rc.local,添加須要開機啓動的任務
#!/bin/bash
echo "test rc " > /var/test.log
四、執行reboot重啓系統,而後查看test.log
sudo reboot