關閉
標題:新版 ubuntu rc.local 作法
內容:
vim /etc/rc.local
內容:
#!/bin/bash
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# 開機要執行的指令
echo "OK" >> /tmp/ok.txt
# 然後其他指令...
exit 0
注意:
一定要有 #!/bin/bash
一定要有 exit 0
chmod +x /etc/rc.local
vim /etc/systemd/system/rc-local.service
[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local
After=network.target
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.target
執行
systemctl daemon-reload
systemctl enable rc-local
systemctl start rc-local