Linux:如何在Debian 9中添加rc.local

时间:2020-02-23 14:39:37  来源:igfitidea点击:

在Debian 9上,传统的" rc.local"已被弃用。
对于传统的Linux用户和管理员,有一种使用SystemD找回它的方法。
请参阅以下步骤:

1.编辑不存在的文件" rc-local.service":

vi /etc/systemd/system/rc-local.service

1.1。
将以下内容添加到" /etc/systemd/system/rc-local.service":

[Unit]
Description=/etc/rc.local
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

2.编辑" rc.local"文件:

vi /etc/rc.local

2.1。
在下面附加通用内容并保存文件:

#!/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

3.更改权限:

chmod +x /etc/rc.local

4.在启动时启用" rc-local"脚本:

systemctl enable rc-local

5.启动" rc-local"脚本:

systemctl start rc-local.service

6.检查启动服务时是否发生任何错误:

systemctl status rc-local.service

现在,您可以将所需的任何内容添加到传统的" rc.local"中。