zoukankan      html  css  js  c++  java
  • Fedora增加rc-local服务开机自启项

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

    增加rc.local配置文件

    vim /etc/rc.d/rc.local

    #!/bin/bash
    nohup /root/frp/frpc -c /root/frp/frpc.ini &
    aria2c --conf-path=/root/Aria2/Aria2.conf -D
    

      Fedora和CentOS的区别:

    • CentOS本身存在/etc/rc.local配置文件,可以直接再此增加内容
    • CentOS配置文件中无须增加#!/bin/bash字头

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

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

    [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服务开机自启时出现如下报错:

        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

  • 相关阅读:
    Silverlight不能调试问题(转摘) Unable to start debugging. Cannot locate Microsoft Internet Explorer.
    Mac OS X 同 Windows 的概念,词汇,热键对比随录,让你更好地过度到Mac OS X
    敏捷度和成熟度
    有什么是安全的吗?
    linux定时任务的设置
    javascript闭包
    (转)JavaScript世界的一等公民 函数
    PHP魔法函数(转)
    JS字符串截取,按字节截取
    linux cp命令
  • 原文地址:https://www.cnblogs.com/Cherry-Linux/p/11119532.html
Copyright © 2011-2022 走看看