zoukankan      html  css  js  c++  java
  • Ubuntu 18.04 设置开机启动脚本 rc.local systemd

    ubuntu18.04不再使用initd管理系统,改用systemd

    ubuntu-18.04不能像ubuntu14一样通过编辑rc.local来设置开机启动脚本,通过下列简单设置后,可以使rc.local重新发挥作用。

    1.建立rc-local.service文件

    $ sudo vi /etc/systemd/system/rc-local.service

    2.复制以下内容

    [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
    1) [Unit] 区块:启动顺序与依赖关系。
    
    2) [Service] 区块:启动行为,如何启动,启动类型。
    
    3) [Install] 区块,定义如何安装这个配置文件,即怎样做到开机启动。
    有关说明

    3. 创建我们自定义的启动脚本(以后自己的脚本在这里面添加即可)

    $ 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.
    touch /home/xxx/`date +%Y-%m-%d`.log 
    echo "`df`" >  /home/xxx/`date +%Y-%m-%d`.log  
    echo "看到这行字,说明添加自启动脚本成功。" > /usr/local/test.log
    exit 0
    #!/bin/sh -e
    
    -e 参数可以让脚本执行遇到错误就不往下执行
    有关说明
    $ sudo chmod +x /etc/rc.local && sudo systemctl enable rc-local
    Created symlink /etc/systemd/system/multi-user.target.wants/rc-local.service → /etc/systemd/system/rc-local.service.
    

    启动服务,并检查服务(非必要)

    $ 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:
      Drop-In: /lib/systemd/system/rc-local.service.d
               └─debian.conf
       Active: active (exited) since Fri 2019-01-25 09:31:07 CST; 9s ago
      Process: 17588 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)
    
    Jan 25 09:31:07 SCHIPS systemd[1]: Starting /etc/rc.local Compatibility...
    Jan 25 09:31:07 SCHIPS systemd[1]: Started /etc/rc.local Compatibility.
    



    参考:

    https://www.jianshu.com/p/79d24b4af4e5

    https://www.cnblogs.com/defifind/p/9285456.html

  • 相关阅读:
    nput keyup 500ms 延时输入 事件处理
    browser-sync默认地址如何转成127.0.0.1
    overflow:scroll-css知识备忘
    圆角的css样式
    支付宝开发
    C#代码与javaScript函数的相互调用
    高性能web开发 如何加载JS,JS应该放在什么位置?
    Makefile自动生成头文件依赖
    一步步教你如何写Makefile
    (一):U-BOOT启动分析--概述
  • 原文地址:https://www.cnblogs.com/schips/p/10318078.html
Copyright © 2011-2022 走看看