1、前言
在当下,主流的Linux已经没有rc.local这个文件了,因为这些主流Linux已经将rc服务化了,因此如果需要使用rc.local,则需要自行创建相关文件,为简化操作,特将相关操作整理为shell脚本,该脚本可一键执行,代码如下:
#相关代码已经在debian和OpenEuler上测试通过!
#/bin/bash
function createRc_local(){
cat << EOF > /etc/systemd/system/rc-local.service
[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.target
EOF
systemctl enable rc-local.service
cat << EOF > /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.
EOF
chmod +x /etc/rc.local
}
createRc_local