Rat's

Debian 9/Ubuntu 17+Add the method of rc.local startup
Note: In many cases, some programs or scripts need to be booted automatically. The simplest way is to use rc.local for booting. However, due to the change of system version
Scan the QR code on the right to read the full text
thirteen
2018/05

Debian 9/Ubuntu 17+Add the method of rc.local startup

explain: In many cases, some programs or scripts need to be added to boot automatically. The easiest way is to use rc.local Since the system is started, many new versions of the system do not have rc.local Files, such as Debian 9 Ubuntu 17.10 Ubuntu 18.04 At this time, we need to set it manually.

method

1. Add rc-local.service

 #The following is a whole command, copied and run together cat > /etc/systemd/system/rc-local.service <<EOF [Unit] Description=/etc/rc.local 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 EOF

2. New rc local file

 #The following is a whole command, copied and run together cat > /etc/rc.local <<EOF #!/ bin/sh # # 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 EOF

3. Add permissions and set the power on auto start

 chmod +x /etc/rc.local systemctl enable rc-local systemctl start rc-local.service

Inspection status:

 systemctl status rc-local.service

return Active:active Information, success.

Finally, we can /etc/rc.local The auto start command for power on is added. Remember to add exit 0 Before.

Vultr New user registration send one hundred USD/ sixteen Each computer room is charged by hour, and Alipay is supported【 Click to view 】。
Last modification: 12:57 AM, February 21, 2020

Comment

18 comments

  1. Tianrun Blog

    Boss, the last sentence of/etc/rc. loacl is wrong '/etc/rc. local'

    1. Rat's
      @Tianrun Blog

      Well, thanks for reminding

  2. lisa1936

    I feel dizzy. I am valid in debian9 of gcp
    But it does not work in the debian based armbian.
    After starting armbian, run it again
    systemctl restart rc-local
    He just executed the contents~
    Help~

    1. Rat's
      @lisa1936

      Armbian hasn't tried yet.

    2. hunter
      @lisa1936

      It's the same with me

  3. Make yourself at home

    Do not "- e" in the first line of the rc.local file, or an error will be reported during startup.

    1. Rat's
      @Make yourself at home

      I have been using this all the time, and I haven't reported any mistakes, but it has just been removed

  4. One - Spirit

    Moderator
    Re.local is placed in/etc/rc.local
    Is the rc-local.service file placed in the
    /etc/systemd/system/rc-local.service

    1. Rat's
      @One - Spirit

      Yes, see the tutorial path.

      1. One - Spirit
        @Rat's

        Re.local is placed in/etc/rc.local
        Rc-local.service is placed in/etc/systemd/system/rc-local.service
        Execute systemctl enable rc local
        Prompt an error
        Failed to enable unit:File rc-local.service:Invalid argument
        How does this need to come out? I use Ubuntu 18.04

        1. Rat's
          @One - Spirit

          Is your file name wrong? I just tested it with Vultr, and it's OK.

  5. Li

    Why doesn't my settings take effect.... The status is always closed..

    1. Rat's
      @Li

      You come step by step. What's your system?

  6. It's hard to fly

    The blogger also found out

    1. Rat's
      @It's hard to fly

      I've discovered it for a long time, but now I just bring out a water article.

      1. Xiaobai's pain
        @Rat's

        Boss, I have followed the tutorial, but I still can't start the NPS automatically
        I edited/etc/rc.loacl with the command nano/etc/rc.loacl, as follows:
        cat > /etc/rc.local <<EOF

        !/ bin/sh -erc.localThis script is executed at the end of each multiuser runlevel. Make sure that the script will "exit 0" on success or any othervalue on error. In order to enable or disable this script just change the executionbits. By default this script does nothing.

        /root/nps/./ nps start

        exit 0
        EOF
        Then I Ctrl+O and Enter, and Ctrl+X quit.
        The following commands are added:
        chmod +x /etc/rc.local
        systemctl enable rc-local
        systemctl start rc-local.service
        Then I checked with systemctl status rc-local.service. The feedback content is:
        rc-local.service - /etc/rc.local
        Loaded: loaded (/etc/systemd/system/rc-local.service; enabled; vendor prese
        Drop-In: /lib/systemd/system/rc-local.service. d

        └─debian.conf

        Active: active (exited) since Mon 2019-10-14 11:23:43 UTC; 15min ago
        Process: 456 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)

        Tasks: 0 (limit: 4915)

        CGroup: /system.slice/rc-local.service

        Oct 14 11:23:43 ip-172-26-33-133 systemd[1]: Starting /etc/rc.local...
        Oct 14 11:23:43 ip-172-26-33-133 systemd[1]: Started /etc/rc.local.
        Boss, can you direct which step is wrong next?

        1. Rat's
          @Xiaobai's pain

          Put/root/nps// Replace nps start with cd/root/npm&&/ Nps start

          1. Xiaobai's pain
            @Rat's

            Well, thank you for your answer.