Debian 9 开机自动运行脚本

问题背景:想要在debian9系统中,自动执行系统reboot测试。
最简单的方式是把reboot测试脚本添加到/etc/rc.local中(exit 0)之前
Debian9 默认没有/etc/rc.local文件,但是可以通过systemd恢复。
首先,我们需要修改rc.local.service文件

#vim  /lib/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

其次,新建/etc/rc.loca文件,加入以下内容:
# vim /etc/rc.local  
#!/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

然后,修改rc.local 权限
# chmod +x /etc/rc.local

之后,就可以启动rc-local了
#systemctl start rc-local

查看rc-local启动过程中是否有错误出现
#systemctl status rc-local

到这里,rc-local就能够正常工作了。

根据需要,将开机自动reboot测试脚本放在/etc/rc.local 中exit 0 之前,就可以开机自动执行了。

# vim /etc/rc.local  
#!/bin/sh -e

……

/sbin/reboot

exit 0

保存退出之后,reboot系统重启即可。
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值