Fedora

How to List Startup Services at Boot Time in Fedora Linux?

Red Hat invented the ‘systemd’ as a manager for system and service on Linux OS. It is compatible with the old SysV and LSB init scripts with more features such as simultaneous start-up of system services at boot time, daemon (background process) activation on-demand, or service control logic based on dependency.

Systemd brings the concept of systemd units in Linux. For e.g., service unit, target unit, mount unit etc. are unit types with file extension as .service, .target, .mount respectively. The configurational file representing these units are stored inside the directories: /usr/lib/systemd/system/, /run/systemd/system/, /etc/systemd/system/

Earlier versions of Red Hat Enterprise Linux (RHEL) used init scripts. These scripts were written in BASH and were located in the directory “/etc/rc.d/init.d/”. These are scripts used to control the services and daemons. Later in RHEL 7, service units were introduced to replace the init scripts. Fedora, which is an upstream OS of Red Hat Enterprise Linux, has started using the systemd from the Fedora version 15.

Service units have .service file extensions and have similar roles as init scripts. “Systemd” uses the “systemctl” utility to manage system services. It can be used to view, start, stop, restart, enable or disable these services.

Advantages of Systemd Over Init System

  1. With systemd, we can prioritize necessary services over less significant services.
  2. Cgroups are used by systemd to keep track of processes and control the execution.environment.
  3. Systemd still supports the old init process and has more control.
  4. Systemd is capable of dealing with dynamic system configuration modifications.

What Will We Cover?

In this guide, we will learn about managing systemd processes. We will see how to enable and disable startup services at boot and how to do service operations like start, stop, restart, etc. We have performed the below exercises on Fedora 30 workstations, which will be most applicable to other Linux OSes.

List Startup Services at Boot in Fedora Linux

The old SysV method uses the service and chkconfig commands to manage the services. These commands are now replaced with the systemd commands like systemctl. Let us see some of the operations of “systemctl” on various services in Linux.

1. To list all the services running on your system, along with their states (enabled or disabled), use the command below:

$ sudo systemctl list-unit-files --type=service

A service can have three states: 1) enabled 2) disabled 3) static

An enabled service has a symlink in a .wants directory, whereas a disabled service does not have one. A static service does not have an install section in the corresponding init script. So, it cannot be enabled or disabled.

To get more details of the services, the below command should be used.

$ sudo systemctl -at service

Summary of the above column names:

UNIT — systemd unit name (here a service name).
LOAD — Specify if the systemd unit was loaded correctly or not.
ACTIVE — State of the unit (here service).

SUB — A sub-state of a unit activation.
DESCRIPTION — A short info of the unit.

We can also use the following command:

$ sudo ls /lib/systemd/system/*.service

or

$ sudo /etc/systemd/system/*.service

The “/etc/inittab” is now replaced by “/etc/systemd/system/” in systemd. This directory now contains the symlinks to the files in the directory “/usr/lib/systemd/system”. The init scripts are placed in the “/usr/lib/systemd/system”. A service must be mapped to “/etc/systemd/system/” for starting it at system boot. For this purpose, the systemctl command is used in Fedora and other latest Linux systems.

2. Let us see the below example of enabling the httpd service:

$ sudo systemctl enable httpd.service

Also, we can use the command below to filter all the enabled services:

$ sudo systemctl list-unit-files | grep enabled

or use the command:

$ sudo systemctl | grep running



3.
To list all the active (running) services, use the command:

$ sudo systemctl -t service --state=active

4. To see which services are enabled to start automatically on system boot, we can also use the following command:

$ sudo systemctl list-unit-files --type=service --state=enabled --all

5. Similarly, we can check the services disabled to start at boot with the command:

$ sudo systemctl list-unit-files --type=service --state=disabled --all

6. We can also see what time each service is taking at startup:

$ sudo systemd-analyze blame

7. To check if a service is enabled for autostart at boot, use the command:

$ sudo systemctl is-enabled xxx

Put the name of service in place of xxx. E.g., in the case of httpd service, the command will be:

$ sudo systemctl is-enabled httpd.service

or

$ sudo systemctl is-enabled httpd

8. To check the status of a service, use the command:

$ sudo systemctl status xxx.service

For example, to check the status of the sshd service:

$ sudo systemctl status sshd.service

9. To check if a service is running or not, just run the below command:

$ sudo systemctl is-active xxx.service

For example, to check the telnet status:

$ sudo systemctl is-active telnet.service

10. To start a dead or inactive service, use the command:

$ sudo systemctl start xxx.service

For example, to start an sshd service:

$ sudo systemctl start sshd



11.
To disable a service at system boot

$ sudo systemctl disable xxx

For example, to disable the httpd service:

$ sudo systemctl disable httpd.service

or

$ sudo systemctl disable httpd

12. To restart a running service

$ sudo systemctl restart xxx.service

To restart the sshd service, use the command:

$ sudo systemctl restart sshd

If the service is not already running, it will be started.

13. To reload a running service

$ sudo systemctl reload xxx.service

For example, reload the httpd service with:

$ sudo systemctl reload httpd.service

This command reloads the configuration of a specific service. To reload the unit configuration file of systemd, we need the command:

$ sudo systemctl daemon-reload

14. To list all the dependencies of a service:

$ sudo systemctl list-dependencies xxx.service

In the case of httpd service, the command will be:

$ sudo systemctl list-dependencies httpd.service

Conclusion

In this guide, we have seen various ways of managing services with systemd utility like enabling services at boot time, starting and stopping them, etc. If you were used to the service command of old Sysvinit, you should switch to systemd as it has more features and it is the default init system in newer versions of Fedora, RHEL, and most of the other major Linux distributions.

About the author

Ali Imran Nagori

Ali imran is a technical writer and Linux enthusiast who loves to write about Linux system administration and related technologies. You can connect with him on LinkedIn
.