Fedora增长rc-local服务开机自启项

  最近新装了一台Fedora 30系统,服务已经正常运行起来了,可是偶然发现当个人系统重启后,写在rc.local配置文件里的命令竟然没生效,致使我系统重启,可是服务却没有正常运行,后来通过一番查阅发现原来Fedora配置开机自启和CentOS存在一些区别,特此记录。vim

增长rc.local配置文件

vim /etc/rc.d/rc.localbash

#!/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字头

在rc-local.service中添加Install字段

vim /lib/systemd/system/rc-local.serviceui

[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.servicecode

相关文章
相关标签/搜索