Fedora增加rc-local服务开机自启项
<p> 最近新装了一台Fedora 30系统,服务已经正常运行起来了,但是偶然发现当我的系统重启后,写在rc.local配置文件里的命令居然没生效,导致我系统重启,但是服务却没有正常运行,后来经过一番查阅发现原来Fedora配置开机自启和CentOS存在一些区别,特此记录。</p><h2 id="增加rclocal配置文件">增加rc.local配置文件</h2>
<p><code>vim /etc/rc.d/rc.local</code></p>
<pre><code>#!/bin/bash
nohup /root/frp/frpc -c /root/frp/frpc.ini &
aria2c --conf-path=/root/Aria2/Aria2.conf -D
</code></pre>
<blockquote>
<p> Fedora和CentOS的区别:</p>
<ul>
<li>CentOS本身存在<code>/etc/rc.local</code>配置文件,可以直接再此增加内容</li>
<li>CentOS配置文件中无须增加<code>#!/bin/bash</code>字头</li>
</ul>
</blockquote>
<h2 id="在rc-localservice中添加install字段">在rc-local.service中添加<code>Install</code>字段</h2>
<p><code>vim /lib/systemd/system/rc-local.service</code></p>
<pre><code>
Description=/etc/rc.d/rc.local Compatibility
Documentation=man:systemd-rc-local-generator(8)
ConditionFileIsExecutable=/etc/rc.d/rc.local
After=network.target
Type=forking
ExecStart=/etc/rc.d/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no
WantedBy=multi-user.target
</code></pre>
<blockquote>
<p> 如果不存在<code>Install</code>字段可能在设置rc-local服务开机自启时出现如下报错:</p>
</blockquote>
<pre><code> The unit files have no installation config (WantedBy, RequiredBy, Also, Alias
settings in the 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.
</code></pre>
<h2 id="授权文件并启动设置开机自启">授权文件并启动设置开机自启</h2>
<p><code>chmod +x /etc/rc.d/rc.local</code><br>
<code>systemctl enable rc-local.service</code><br>
<code>systemctl start rc-local.service</code><br>
<code>systemctl status rc-local.service</code></p>
</div>
<div id="MySignature" role="contentinfo">
作者:Federico Sun <br>
博客地址:https://www.cnblogs.com/Cherry-Linux <br>
座右铭:人总是这么痛苦吗?还是只有小时候这样?总是如此。<br><br>
来源:https://www.cnblogs.com/Cherry-Linux/p/11119532.html
頁:
[1]