ubuntu
ubuntu 18 开机自启
- 编辑
vim /lib/systemd/system/rc-local.service
[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
- 设置开机自启systemctl enable rc.local.service
- 启动服务并检查状态
systemctl start rc-local.service
systemctl status rc-local.service
-
创建文件并赋予可执行权限 touch /etc/rc.local;chmod +x /etc/rc.local
-
下列内容复制进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
####