你若安好
便是晴天

Ubuntu18设置rc.local开机自启动

/etc/systemd/system/rc-local.service文件中追加以下内容

[Install]
WantedBy=multi-user.target

创建文件sudo touch /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.
echo "看到这行字,说明添加自启动脚本成功。" > /usr/local/test.log
exit 0

给rc.local加上权限

sudo chmod +x /etc/rc.local

启用服务

sudo systemctl enable rc.local

启动服务并检查状态

sudo systemctl start rc.local.service
sudo systemctl status rc.local.service

重启并检查test.log文件中的内容,确认脚本是否启动成功

cat /usr/local/test.log
原创作品未经允许不得转载:WTF博客 » Ubuntu18设置rc.local开机自启动

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址