美文网首页
Debian/Ubuntu添加rc.local文件并设置开机启动

Debian/Ubuntu添加rc.local文件并设置开机启动

作者: 灼灼其华啦 | 来源:发表于2019-11-15 21:17 被阅读0次

    哎呀,折腾死我了,有幸看到这篇帖子,我就转载一下吧。

    比较新的Linux发行版已经没有rc.local文件了。因为已经将其服务化了。但是WiKi只给了rc.local的说明,自己尝试了systemctl又不成功。 参考:https://www.linuxidc.com/Linux/2019-09/160737.htm

    # 配置service文件
    sudo nano /etc/systemd/system/rc-local.service
    
    [Unit]
     Description=/etc/rc.local Compatibility
     ConditionPathExists=/etc/rc.local
    
    [Service]
     Type=forking
     ExecStart=/etc/rc.local start
     TimeoutSec=0
     StandardOutput=tty
     RemainAfterExit=yes
     SysVStartPriority=99
    
    [Install]
     WantedBy=multi-user.target
    
    # 激活rc-local.service
    sudo systemctl enable rc-local.service
    
    # 添加启动服务
    
    #!/bin/sh -e
    #
    # rc.local
    #
    # This script is executed at the end of each multiuser runlevel.
    # Make sure that the script will "exit 0" on success or any other
    # value on error.
    #
    # In order to enable or disable this script just change the execution
    # bits.
    #
    # By default this script does nothing.
    
    # exit 0 前面添加需要开机启动的命令
    /home/pi/shutdown.py
    exit 0
    
    # 赋予执行权限
    sudo chmod +x /etc/rc.local
    
    • 重启测试
    orangepi@OrangePi:~$ sudo systemctl status rc-local.service
    [sudo] password for orangepi: 
    ● rc-local.service - /etc/rc.local Compatibility
       Loaded: loaded (/etc/systemd/system/rc-local.service; enabled; vendor preset: enabled)
      Drop-In: /lib/systemd/system/rc-local.service.d
               └─debian.conf
       Active: active (running) since Fri 2019-11-15 21:07:20 CST; 1min 32s ago
      Process: 518 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)
     Main PID: 520 (java)
        Tasks: 15 (limit: 4915)
       CGroup: /system.slice/rc-local.service
               └─520 java -jar /home/orangepi/blynk/server-0.41.11-java8.jar -dataFolder /home/orangepi/blynk
    
    Nov 15 21:07:20 OrangePi systemd[1]: Starting /etc/rc.local Compatibility...
    Nov 15 21:07:20 OrangePi systemd[1]: Started /etc/rc.local Compatibility.
    Nov 15 21:08:25 OrangePi rc.local[518]: Blynk Server  successfully started.
    Nov 15 21:08:25 OrangePi rc.local[518]: All server output is stored in folder '/logs' file.
    Warning: rc-local.service changed on disk. Run 'systemctl daemon-reload' to reload units.
    orangepi@OrangePi:~$ systemctl daemon-reload
    
    
    

    相关文章

      网友评论

          本文标题:Debian/Ubuntu添加rc.local文件并设置开机启动

          本文链接:https://www.haomeiwen.com/subject/evfeictx.html