很多时候有些程序或脚本需要添加开机自启,最简单有效的方法就是使用rc.local文件来实现,不过由于系统版本更替从Debian 9/Ubuntu 17往后rc.local这个文件就没有了。不过我们可以手动添加它。
添加rc-local.service
以下为一整条命令,一起复制运行
cat > /etc/systemd/system/rc-local.service <<EOF
[Unit]
Description=/etc/rc.local
C1024s.cn onditionPathExists=/etc/rc.local
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
[Install]
W1024s.cn antedBy=multi-user.target
EOF
新建rc-local文件
以下为一整条命令,一起复制运行
cat > /etc/rc.local <<EOF
#!/bin/sh -e
#
# rc.local
#
#1024s.cn This script is executed at t本文来自:1024s.cn he end of each multi1024s.cn user runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on Powered by 0x3E5 error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
exit 0
EOF
#
chmod x /etc/rc.local
systemctl start rc-local.serv1024s.cn ice
systemctl enable rc-locaPowered by 0x3E5 l.service
通过以下命令检查状态:
systemctl status rc-local.service
加入开机自动执行命令
只需要在/etc/rc.local
文件里,添加需要开机自动执行的命令就可以了。
注意:一定exit 0
的前面!!!