Why and How to Enable rc.local Support with Systemd
Abstract
When you are running a recent modern Linux distro that uses Systemd to manage services, init functions like rc.local are not supported anymore. This guide explains why and how to enable /etc/rc.local to run on linux system at boot time.
1 Introduction
In Linux, init is a abbreviation for Initialization. The init is a daemon process which starts as soon as the computer starts and continue running till, it is shutdown. In-fact init is the first process that starts when a computer boots, making it the parent of all other running processes directly or indirectly and hence typically it is assigned“pid=1“.
If somehow init daemon could not start, no process will be started and the system will reach a stage called “Kernel Panic“. init is most commonly referred to as System V init.
A init process starts serially i.e.,one task starts only after the last task startup was successful and it was loaded in the memory. This often resulted into delayed and long booting time.
The need to replace init with something more perfect was felt from a long time and several alternatives were developed from time-to-time, some of which became distribution’s native init replacement, some of which are:
- Upstart – A init replacement daemon implemented in Ubuntu GNU/Linux and designed to start process asynchronously.
- Epoch – A init replacement daemon built around simplicity and service management, designed to start process single-threaded.
- Mudar – A init replacement daemon written in Python, implemented on Pardus GNU/Linux and designed to start process asynchronously.
- Systemd – A init replacement daemon designed to start process in parallel,implemented in a number of standard distribution – Fedora, OpenSuSE, Arch,RHEL, CentOS, etc.
2 How
Systemd, which was created by Red Hat's Lennart Poettering and Kay Sievers, does more than start the core programs running. It provides a standard process for controlling what programs run when a Linux system boots up. Systemd is named with UNIX-like convention to add ‘d’ at the end of daemon. So that they can be easily recognized.
It was designed to overcome the short coming of init. It itself is a background processes which is designed to start processes in parallel, thus reducing the boot time and computational overhead.
Steps to create a rc-local service is as follows:
1) Create service file rc-local.service” in /etc/systemd/system:
#sudo vim /etc/systemd/system/rc-local.service
With the following contents:
[Unit]
Description=/etc/rc.local compatibility
ConditionPathExists=/etc/rc.local
# add your require service dependency
#Requires=netctl@inner.service
# After service
After=syslog.target network.target network-online.target
[Service]
#Type=forking
Type=oneshot
#script to run, here add one parameter of'start'
ExecStart=/etc/rc.local start
# disable timeout logic
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
GuessMainPID=no
# not supprted now
SysVStartPriority=99
[Install]
WantedBy=multi-user.target
2) create /etc/rc.local and make it execuable:
#sudo vim /etc/rc.local
#sudo chmod +x /etc/rc.local
This file’s content should begin as:
#!/bin/sh
# other script you want to add ……
3) make the sevice to run at system boot
#sudo systemctl enable rc-local
3 Conclusion
- In order to get rc-local compatible with Systemd, rc-local servicehas been implemented to run rc.local startup script at system boot time.
- To avoid failures of shell command in rc.local, the service must runsAfter many dependency services such as network service and others.
- Also file rc.local must be a valid executable shell script file.
rc-local.service is Here:https://github.com/wangyq/ShellUtil/blob/master/rc-local.service
That is all.
Anything running as pid=1 must not break,must not be mess and must be controlled by users effectively and efficiently.Many-a-user believes that replacing init for systemd is nothing more than reinventing the wheel every time as a side effect of Linux. But this is the diverse nature of Linux. This is because Linux is that much powerful. Change is good and we must appreciate it if it is for a good reason.