In Linux, whenever we install any packages which has services or daemons. By default all the services “init & systemd” scripts will be added into it but it wont be enabled.
Hence, we need to enable or disable the service manually if it’s required. There are three major init systems are available in Linux which are very famous and still in use.It’s a important topic for Linux admin so, everyone should be aware of this and practice how to use this in the efficient way.
What is init System?
In Linux/Unix based operating systems, init (short for initialization) is the first process that started during the system boot up by the kernel.It’s holding a process id (PID) of 1. It will be running in the background continuously until the system is shut down.
Init looks at the
/etc/inittab file to decide the Linux run level then it starts all other processes & applications in the background as per the run level.
BIOS, MBR, GRUB and Kernel processes were kicked up before hitting init process as part of Linux booting process.
Below are the available run levels for Linux (There are seven runlevels exist, from zero to six).
1:Single user mode
2:Multiuser, without NFS
3:Full multiuser mode
5:X11 (GUI – Graphical User Interface)
Below three init systems are widely used in Linux.
- System V (Sys V)
What is System V (Sys V)?
System V (Sys V) is one of the first and traditional init system for Unix like operating system. init is the first process that started during the system boot up by the kernel and it’s a parent process for everything.
Most of the Linux distributions started using traditional init system called System V (Sys V) first. Over the years, several replacement init systems were released to address design limitations in the standard versions such as launchd, the Service Management Facility, systemd and Upstart.
But systemd has been adopted by several major Linux distributions over the traditional SysV init systems.
What is Upstart?
Upstart is an event-based replacement for the /sbin/init daemon which handles starting of tasks and services during boot, stopping them during shutdown and supervising them while the system is running.
It was originally developed for the Ubuntu distribution, but is intended to be suitable for deployment in all Linux distributions as a replacement for the venerable System-V init.
It was used in Ubuntu from 9.10 to Ubuntu 14.10 & RHEL 6 based systems after that they are replaced with systemd.
What is systemd?
Systemd is a new init system and system manager which was implemented/adapted into all the major Linux distributions over the traditional SysV init systems.
systemd is compatible with SysV and LSB init scripts. It can work as a drop-in replacement for sysvinit system. systemd is the first process get started by kernel and holding PID 1.
It’s a parant process for everything and Fedora 15 is the first distribution which was adapted systemd instead of upstart. systemctl is command line utility and primary tool to manage the systemd daemons/services such as (start, restart, stop, enable, disable, reload & status).
systemd uses .service files Instead of bash scripts (SysVinit uses). systemd sorts all daemons into their own Linux cgroups and you can see the system hierarchy by exploring
How to Enable/Disable Services on Boot Using chkconfig Commmand?
The chkconfig utility is a command-line tool that allows you to specify in which
runlevel to start a selected service, as well as to list all available services along with their current setting.
Also, it will allows us to enable or disable a services from the boot. Make sure you must have superuser privileges (either root or sudo) to use this command.
All the services script are located on
How to Check All Services Along with their run-level Information?
-–list parameter displays all the services along with their current status (What run-level the services are enabled or disabled).
# chkconfig --list NetworkManager 0:off 1:off 2:on 3:on 4:on 5:on 6:off abrt-ccpp 0:off 1:off 2:off 3:on 4:off 5:on 6:off abrtd 0:off 1:off 2:off 3:on 4:off 5:on 6:off acpid 0:off 1:off 2:on 3:on 4:on 5:on 6:off atd 0:off 1:off 2:off 3:on 4:on 5:on 6:off auditd 0:off 1:off 2:on 3:on 4:on 5:on 6:off . .
How to Check a Particular Service’s run-level Status?
If you would like to see a particular service status in run-level then use the following format and grep the required service.
In this case, we are going to check the
auditd service status in run-level.
# chkconfig --list| grep auditd auditd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
How to enable a particular service on run-level?
--level parameter to enable a service in the required run-level. In this case, we are going to enable
httpd service on run-level 3 and 5.
# chkconfig --level 35 httpd on
How to disable a particular service on run-level?
--level parameter to disable a service in the required run-level. In this case, we are going to enable
httpd service on run-level 3 and 5.
# chkconfig --level 35 httpd off or # chkconfig httpd off
How to add a new service to the Startup List?
-–add parameter allows us to add any new service to the startup. By default, it will turn on level 2, 3, 4 and 5 automatically for that service.
# chkconfig --add nagios
How to remove a service from Startup List?
--del parameter to remove the service from the startup list. Here, we are going to remove the Nagios service from the startup list.
# chkconfig --del nagios
How to Enable/Disable Services on Boot using systemctl Command?
systemctl is command line utility and primary tool to manage the systemd daemons/services such as (start, restart, stop, enable, disable, reload & status).
All the created systemd unit files are located on
How to list all services?
Use the following command to list all the services which included enabled and disabled.
# systemctl list-unit-files --type=service UNIT FILE STATE arp-ethers.service disabled auditd.service enabled [email protected] enabled blk-availability.service disabled brandbot.service static [email protected] static chrony-wait.service disabled chronyd.service enabled cloud-config.service enabled cloud-final.service enabled cloud-init-local.service enabled cloud-init.service enabled console-getty.service disabled console-shell.service disabled [email protected] static cpupower.service disabled crond.service enabled . . 150 unit files listed.
If you would like to see a particular service status then use the following format and grep the required service. In this case, we are going to check the
httpd service status.
# systemctl list-unit-files --type=service | grep httpd httpd.service disabled
How to enable a particular service on boot?
Use the following systemctl command format to enable a particular service. To enable a service, it will create a symlink. The same can be found below.
# systemctl enable httpd Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
Run the following command to double check whether the services is enabled or not on boot.
# systemctl is-enabled httpd enabled
How to disable a particular service on boot?
Use the following systemctl command format to disable a particular service. When you run the command, it will remove a symlink which was created by you while enabling the service. The same can be found below.
# systemctl disable httpd Removed symlink /etc/systemd/system/multi-user.target.wants/httpd.service.
Run the following command to double check whether the services is disabled or not on boot.
# systemctl is-enabled httpd disabled
How to check current system run level Information?
Use the following systemctl command to verify which run-level you are in. Still “runlevel” command works with systemd, however runlevels is a legacy concept in systemd so, I would like to advise you to use systemctl command for all activity.
We are in
run-level 3, the same is showing below as
# systemctl list-units --type=target UNIT LOAD ACTIVE SUB DESCRIPTION basic.target loaded active active Basic System cloud-config.target loaded active active Cloud-config availability cryptsetup.target loaded active active Local Encrypted Volumes getty.target loaded active active Login Prompts local-fs-pre.target loaded active active Local File Systems (Pre) local-fs.target loaded active active Local File Systems multi-user.target loaded active active Multi-User System network-online.target loaded active active Network is Online network-pre.target loaded active active Network (Pre) network.target loaded active active Network paths.target loaded active active Paths remote-fs.target loaded active active Remote File Systems slices.target loaded active active Slices sockets.target loaded active active Sockets swap.target loaded active active Swap sysinit.target loaded active active System Initialization timers.target loaded active active Timers