美文网首页
八.Ubutu18.04系统添加开机自启动脚本

八.Ubutu18.04系统添加开机自启动脚本

作者: 妄语莫言 | 来源:发表于2019-06-22 21:21 被阅读0次

    参考文章:https://www.cnblogs.com/airdot/p/9688530.html
    RedHat系列以及Ubuntu14可以通过编辑rc.local来设置开机启动脚本,Ubutu18.04就需要添加开机自启动的服务来恢复rc.local的功能。
    1、建立rc-local.service文件,添加如下内容:

    sudo vi /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
    ############################################################
    

    2.创建rc.local文件并添加如下内容:

    sudo vi /etc/rc.local
    ############################################################
    #!/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.
    echo "111111111111" > /usr/local/test.log
    exit 0
    ############################################################
    

    3.给rc.local加上执行权限

    sudo chmod +x /etc/rc.local
    

    4.启动服务并添加开机自启动以及查看服务状态

    sudo systemctl enable rc-local
    sudo systemctl start rc-local.service
    sudo systemctl status rc-local.service
    ############################################################
    ● 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 (exited) since Sat 2019-06-22 18:13:55 CST; 11s ago
      Process: 2907 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)
    
    6月 22 18:13:55 turingvideo-virtual-machine systemd[1]: Starting /etc/rc.local Compatibility...
    6月 22 18:13:55 turingvideo-virtual-machine systemd[1]: Started /etc/rc.local Compatibility.
    
    ############################################################
    

    5.重启系统后检查test.log文件确认开机是否加载启动脚本

    cat /usr/local/test.log 
    

    相关文章

      网友评论

          本文标题:八.Ubutu18.04系统添加开机自启动脚本

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