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

  • 相关阅读:
    win10自带邮箱应用无法查看qq邮箱应用解决办法
    Ubuntu紫色背景颜色代码
    VMware中对Linux虚拟机的网络配置静态IP的配置
    CentOS 7在VMware 12中共享文件看不见的问题?
    C++中让人忽视的左值和右值
    C++ allocator类学习理解
    C++11新特性 -----> 右值引用 &&
    重新认识new
    关于C++中nothrow的某某某
    stopPropagation, preventDefault 和 return false 的区别
  • 原文地址:https://www.cnblogs.com/Cherry-Linux/p/11119532.html
Copyright © 2011-2022 走看看