centos8 遇到无法启动rc.local

分类:Linux,问题集 | 作者:凹凸曼 | 发表于2021/06/08 centos8 遇到无法启动rc.local已关闭评论

一般情况加入:chmod +x /etc/rc.d/rc.local 即可解决在此配置文件里加入开机启动

但是我开启执行权限还是不行,查看启动错误信息如下:

[root@172-0-0-205 ~]# systemctl --failed
  UNIT             LOAD   ACTIVE SUB    DESCRIPTION                     
● rc-local.service loaded failed failed /etc/rc.d/rc.local Compatibility

LOAD   = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB    = The low-level unit activation state, values depend on unit type.

如何解决呢?

方法一:

进去了解一下启动服务的规则:

[root@172-0-0-205 ~]# vim /usr/lib/systemd/system/rc-local.service 
#  SPDX-License-Identifier: LGPL-2.1+
#
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

# This unit gets pulled automatically into multi-user.target by
# systemd-rc-local-generator if /etc/rc.d/rc.local is executable.
[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

看里面的配置After=network.target 表示:网络服务器启动后才能正常启动,

我在/etc/rc.local 加入了挂载NFS文件 可能就是这样原因导出,解决办法延迟挂载,让挂载正常即可解决

sleep 3

mount -o nolock ……

当然也可以自己弄一个独立服务把所有指令弄进去

方法二:

#查询启动状态
systemctl status rc-local

#后面增加两行 下面两个的启动失败 间隔30秒重新启动了
vi /usr/lib/systemd/system/rc-local.service
Restart=on-failure
RestartSec=30s

总结:方法一有点不好用推荐还是方法二。

文出自 “凹凸曼” 博客,请务必保留此出处 http://www.apoyl.com/?p=3064

Tag:

日志信息 »

该日志于2021-06-08 09:57由 凹凸曼 发表在Linux, 问题集分类下, 评论已关闭。

目前盖楼

抱歉,评论被关闭

« »