最近新裝了一臺Fedora 30系統,服務已經正常運行起來了,可是偶然發現當個人系統重啓後,寫在rc.local配置文件裏的命令竟然沒生效,致使我係統重啓,可是服務卻沒有正常運行,後來通過一番查閱發現原來Fedora配置開機自啓和CentOS存在一些區別,特此記錄。vim
vim /etc/rc.d/rc.local
bash
#!/bin/bash nohup /root/frp/frpc -c /root/frp/frpc.ini & aria2c --conf-path=/root/Aria2/Aria2.conf -D
Fedora和CentOS的區別:socket
- CentOS自己存在
/etc/rc.local
配置文件,能夠直接再此增長內容- CentOS配置文件中無須增長
#!/bin/bash
字頭
Install
字段vim /lib/systemd/system/rc-local.service
ui
[Unit] Description=/etc/rc.d/rc.local Compatibility Documentation=man:systemd-rc-local-generator(8) ConditionFileIsExecutable=/etc/rc.d/rc.local After=network.target [Service] Type=forking ExecStart=/etc/rc.d/rc.local start TimeoutSec=0 RemainAfterExit=yes GuessMainPID=no [Install] WantedBy=multi-user.target
若是不存在
Install
字段可能在設置rc-local服務開機自啓時出現以下報錯:this
The unit files have no installation config (WantedBy, RequiredBy, Also, Alias settings in the [Install] section, and DefaultInstance for template units). This means they are not meant to be enabled using systemctl. Possible reasons for having this kind of units are: 1) A unit may be statically enabled by being symlinked from another unit's .wants/ or .requires/ directory. 2) A unit's purpose may be to act as a helper for some other unit which has a requirement dependency on it. 3) A unit may be started when needed via activation (socket, path, timer, D-Bus, udev, scripted systemctl call, ...). 4) In case of template units, the unit is meant to be enabled with some instance name specified.
chmod +x /etc/rc.d/rc.local
systemctl enable rc-local.service
systemctl start rc-local.service
systemctl status rc-local.service
code