ubuntu 18.04开机自启动脚本

16.04以上就要用service开机启动了

sudo vim /etc/systemd/system/rc-rc.service

内容为:

[Unit]
Description=/etc/rc Compatibility
ConditionPathExists=/etc/rc
 
[Service]
Type=forking
ExecStart=/etc/rc start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
 
[Install]
WantedBy=multi-user.target
sudo vim /etc/rc

内容为:

#!/bin/sh -e
echo "测试脚本执行成功" > test.log
exit 0
//加权限
sudo chmod 755 /etc/rc
//设置开机启动
sudo systemctl enable rc-rc
//至此开机启动就设置完毕了

//取消开机启动
sudo systemctl disable rc-rc
//立即启动service
sudo systemctl start rc-rc
//查看单个service状态
sudo systemctl status rc-rc

你可能感兴趣的:(linux)