Why and How to Enable rc.local Support with Systemd
2016-11-01 16:32
423 查看
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.
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.
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
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.
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 parentof 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 systemboots 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.
相关文章推荐
- How to find out why your account keeps getting locked with Windows Server, TMG and Webspy
- Howto Enable and Use A2DP Sink on Ubuntu Linux with Bluez
- How to build CP2K with Intel Compiler 12.1, OpenMPI-1.4.3 and Infiniband Support
- Oracle9i新特点:SPFILE的使用--How to set events with spfile and etc
- 为何以及如何使用Netlink Socket ( Why and How to Use Netlink Socket)
- Kernel Korner - Why and How to Use Netlink Socket
- How to build Multi-Language Web Sites with ASP.NET 2.0 and VS.Net 2005
- Kernel Korner - Why and How to Use Netlink Socket
- How to install Nginx, PHP, PHP-FPM and MySQL under Windows with Cygwin
- How to enable USB selective suspend and system wake in the UMDF driver for a USB device
- Why and how to design routines of class
- How-To : Using EJB 3.0 and Java Persistence API with Spring in OC4J
- HOWTO Setup local Portage and Package Mirror
- How to get local machine name and IP address?
- (转贴)How to use JDBC and transactions in Tomcat with JOTM
- How To Configure IIS 6.0 and Tomcat with the JK 1.2 Connector
- (Page 1 of 3 )A walking tour of JavaBeans What JavaBeans is, how it works, and why you want to use it
- How to enable combined dmcl and dfc trace?
- How to Run a Root “/” Site with the VS/VWD 2005 Local Web Server
- (Page 2 of 3 )A walking tour of JavaBeans 2 :What JavaBeans is, how it works, and why you want to use it