为debian11增加rc.local

systemd 默认读取 /etc/systemd/system 下的配置文件,该目录下的文件会链接/lib/systemd/system/下的文件
打开脚本/lib/systemd/system/rc-local.service 添加末尾[Install]几行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[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

之后手动创建/etc/rc.local

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/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.

exit 0

给权限
chmod +x /etc/rc.local
重载
systemctl daemon-reload
启用
systemctl enable rc-local
systemctl start rc-local
看状态
systemctl status rc-local


为debian11增加rc.local
https://hexo.psorai.eu.org/2023/06/06/为debian11增加rc.local/
Author
Sora
Posted on
June 6, 2023
Licensed under