How to enable /etc/rc.local script to run on system startup.
sudo systemctl status rc-local
returns:
○ rc-local.service - /etc/rc.local Compatibility Loaded: loaded (/lib/systemd/system/rc-local.service; static) Drop-In: /usr/lib/systemd/system/rc-local.service.d └─debian.conf Active: inactive (dead) Docs: man:systemd-rc-local-generator(8)
sudo systemctl enable rc-local
may return something like:
The unit files have no installation config (WantedBy=, RequiredBy=, Also=, Alias= settings in the [Install] section, and DefaultInstance= for template units). This means they are not meant to be enabled using systemctl. Possible reasons for having this kind of units are: • A unit may be statically enabled by being symlinked from another unit's .wants/ or .requires/ directory. • A unit's purpose may be to act as a helper for some other unit which has a requirement dependency on it. • A unit may be started when needed via activation (socket, path, timer, D-Bus, udev, scripted systemctl call, ...). • In case of template units, the unit is meant to be enabled with some instance name specified.
NOTE: The unit file has no [Install] section.
sudo vi /etc/systemd/system/rc-local.service
and populate with:
[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
printf '%s\n' '#!/bin/bash' 'exit 0' | sudo tee -a /etc/rc.local
NOTE: Modern versions of Ubuntu do not come with this /etc/rc.local file.
sudo chmod +x /etc/rc.local
sudo systemctl enable rc-local
returns:
Created symlink from /etc/systemd/system/multi-user.target.wants/rc-local.service to /etc/systemd/system/rc-local.service.
sudo systemctl start rc-local.service sudo systemctl status rc-local.service
returns:
● rc-local.service - /etc/rc.local Compatibility Loaded: loaded (/etc/systemd/system/rc-local.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2023-06-02 09:40:46 BST; 5min ago Process: 921 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS) Main PID: 901 (watch) CGroup: /system.slice/rc-local.service