zoukankan      html  css  js  c++  java
  • Ubuntu 20.04开机启动配置

    Ubuntu升级到了20.04之后,默认的rc.local是不启动的,这也就导致了,我配置的一些自定义的脚本是没有办法在开机的时候就自动启动了。

    rc-local.service默认内容如下

    #  SPDX-License-Identifier: LGPL-2.1+
    # 
    #  This file is part of systemd.
    #
    #  systemd is free software; you can redistribute it and/or modify it
    #  under the terms of the GNU Lesser General Public License as published by
    #  the Free Software Foundation; either version 2.1 of the License, or
    #  (at your option) any later version.
    # This unit gets pulled automatically into multi-user.target by
    # systemd-rc-local-generator if /etc/rc.local is executable.
    [Unit]
    Description=/etc/rc.local Compatibility
    Documentation=man:systemd-rc-local-generator(8)
    ConditionFileIsExecutable=/etc/rc.local
    After=network.target
    [Service]
    Type=forking
    ExecStart=/etc/rc.local start
    TimeoutSec=0
    RemainAfterExit=yes
    GuessMainPID=no
    

    这个时候启动的时候会提示没有Install,所以在如上的脚本上增加【Install】,下面是增加完【install】的全量脚本

    #  SPDX-License-Identifier: LGPL-2.1+
    # 
    #  This file is part of systemd.
    #
    #  systemd is free software; you can redistribute it and/or modify it
    #  under the terms of the GNU Lesser General Public License as published by
    #  the Free Software Foundation; either version 2.1 of the License, or
    #  (at your option) any later version.
    # This unit gets pulled automatically into multi-user.target by
    # systemd-rc-local-generator if /etc/rc.local is executable.
    [Unit]
    Description=/etc/rc.local Compatibility
    Documentation=man:systemd-rc-local-generator(8)
    ConditionFileIsExecutable=/etc/rc.local
    After=network.target
    [Service]
    Type=forking
    ExecStart=/etc/rc.local start
    TimeoutSec=0
    RemainAfterExit=yes
    GuessMainPID=no
    
    [Install]
    WantedBy=multi-user.target
    Alias=rc-local.service
    

    根据上面代码中ExecStart,我们编辑/etc/rc.local脚本

    #!/bin/sh
    
    iptables-restore < /etc/iptables.up.rules  #你需要开机自启动的脚本或者命令
    
    exit 0
    

    这里一定要有exit的退出,否则会报错的。

    然后把rc-local.service设置为开机启动

    systemctl start rc-local # 启动
    systemctl restart rc-local # 重启
    systemctl status rc-local # 查看状态,如果是active就表示没问题了
    

  • 相关阅读:
    迅为IMX6ULL开发板-Linux MISC驱动-编写实验程序
    迅为龙芯2K1000开发板快速体验
    迅为3399开发板Android系统-使用strace跟踪系统调用
    迅为imx6ull开发板使用c语言调用shell命令控制led灯
    迅为与龙芯强强联合匠心之作 iTOP-2K1000开发板正式发布
    迅为iTOP3399开发板QT系统PCIE 4G移植-测试程序
    迅为IMX8MM开发板Android编译环境搭建
    bzero和memset函数
    [linux 2021-10-14] linux中启动jar的shell脚本
    重写与重载的区别
  • 原文地址:https://www.cnblogs.com/netflix/p/15035604.html
Copyright © 2011-2022 走看看