建立rc-local.service文件

# vim /etc/systemd/system/rc-local.service

将以下内容复制进去并保存

[Unit]
Description=/etc/rc.local Compatibility
# 脚本文件位置
ConditionPathExists=/etc/rc.local
 
[Service]
Type=forking
# 配置的脚本文件rc.local为start
ExecStart=/etc/rc.local start
TimeoutSec=0  
# 标准输出  
StandardOutput=tty
RemainAfterExit=yes
# 优先级,当有多个开机启动文件时可以设置不同的值
SysVStartPriority=99 
 
[Install]
WantedBy=multi-user.target

生成rc.local

# 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

exit 0之前则为脚本需要执行的操作,保存后提升权限

# chmod 755 /etc/rc.local

启动服务并检查状态

# service rc-local start
# service rc-local status

参考文档

Ubuntu18.04 开机自启动脚本
ubuntu-18.04 设置开机启动脚本

Last modification:September 21, 2019
If you think my article is useful to you, please feel free to appreciate