Skip to content

Latest commit

 

History

History
70 lines (59 loc) · 7.12 KB

rc.local.md

File metadata and controls

70 lines (59 loc) · 7.12 KB

rc.local

If you do not want systemd, consider Devuan.

As I said about CentOS 7 and about Debian 8 and about Ubuntu 15:

You're using a systemd+Linux operating system. /etc/rc.local is a double backwards compatibility mechanism in systemd, because it is a backwards compatibility mechanism for a mechanism that was itself a compatibility mechanism in the van Smoorenburg System 5 rc clone.

Using /etc/rc.local can go horribly wrong. People have been surprised by the fact that systemd doesn't run rc.local in quite the same way, in quite the same place in the bootstrap, as they are used to. (Or erroneously expect: It did not, in fact, run last in the old system, as the OpenBSD manual still points out.) Others have been surprised by the fact that what they set up in rc.local expecting the old ways of doing things, is then completely undone by the likes of new udev rules, NetworkManager, systemd-logind, systemd-resolved, or various "Kit"s.

As exemplified by "https://unix.stackexchange.com/questions/389289/", some operating systems already provide systemd without the backwards compatibility features such as the systemd-rc-local-generator generator. Whilst Debian still retains the backwards compatibility features, Arch Linux builds systemd with them turned off. So on Arch and operating systems like it expect /etc/rc.local to be entirely ignored.

Forget about rc.local. It's not the way to go. You have a systemd+Linux operating system. So make a proper systemd service unit, and don't begin from a point that is two levels of backwards compatibility away. (On Ubuntu and Fedora, it is three times removed, the van Smoorenburg System 5 rc clone that followed rc.local having then been itself twice superseded, over a decade ago, first by upstart and then by systemd.)

Also remember the first rule for migrating to systemd.

This is not even a new idea that is specific to systemd. On van Smoorenburg rc and Upstart systems, the thing to do was to make a proper van Smoorenburg rc script or Upstart job file rather than use rc.local. Even FreeBSD's manual notes that nowadays one creates a proper Mewburn rc script instead of using /etc/rc.local. Mewburn rc was introduced by NetBSD 1.5 in 2000.

/etc/rc.local dates from the time of Seventh Edition Unix and before. It was superseded by /etc/inittab and a runlevel-based rc in AT&T Unix System 3 (with a slightly different /etc/inittab in AT&T Unix System 5) in 1983. Even that is now history.

Create proper native service definitions for your service management system, whether that be a service bundle for the nosh toolset's service-manager and system-control, an /etc/rc.d/ script for Mewburn rc, a service unit file for systemd, a job file for Upstart, a service directory for runit/s6/daemontools-encore, or even an /etc/init.d/ script for van Smoorenburg rc.

In systemd, such administrator-added service unit files go in /etc/systemd/system/ usually (or /usr/local/lib/systemd/system/ rarely). With the nosh service manager, /var/local/sv/ is a conventional place for local service bundles. Mewburn rc on FreeBSD uses /usr/local/etc/rc.d/. Packaged service unit files and service bundles, if you are making them, go in different places, though.

Further reading

-JdeBP answered Sep 27, 2018 at 16:06, Stephen Kitt edited Jan 19 at 9:26 CC BY-SA 4.0

Debian 10

Debian 11

Deprecates rc.local

Workaround

This workaround is not for Devuan 4 Chimaera (based on Debian 11 Bullseye). It has a device called /etc/systemd/system/rc.local.service to emulate rc.local from a systemd perspective but does not have systemd.

A workaround is at Home / Sysadmin / rc.local deprecated by mox.

  • Make a systemd script to emulate rc.local (change "Wants" and "After" depending on what your script does! This one was modified to require networking which is probably good enough for most people.):
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/local/bin/rc.local

[Install]
WantedBy=multi-user.target

[Unit]
Wants=bluetooth.service
After=bluetooth.service
  • Enable it: systemctl enable local-starttasks.service