Linux Systemd

From Free Knowledge Base- The DUCK Project: information for everyone
Jump to: navigation, search

systemd provides an array of system components for Linux operating systems. Its main aim is to unify service configuration and behavior across Linux distributions. It is the controlling interface and inspection tool for the init system and service manager systemd.

systemd replaces [Linux Sys V]] - We used to control system services with commands like "service httpd restart" and now we use instead the awkwardly syntaxed systemctl such as "systemctl restart httpd" or "systemctl restart apache2"

systemd uses the systemctl command

systemctl command

Command	Description
systemctl start [service]		Start a service.
systemctl stop [service]		Stop a service.
systemctl enable [service]		Enable a service to start automatically at system boot.
systemctl disable [service]		Disable a service from starting automatically at system boot.
systemctl status [service]		View the status of a service.
systemctl restart [service]		Restart a service.
systemctl reload [service]		Reload a service's configuration without restarting it.
systemctl mask [service]		Prevent a service from being started.
systemctl unmask [service]		Allow a previously masked service to be started.
systemctl set-default [target]		Change the default system target (runlevel).
systemctl list-unit-files		List all installed unit files and their states.
systemctl list-dependencies [unit]	List the dependencies of a specific unit.
systemctl list-sockets			List all active sockets.
systemctl list-jobs			List all active systemd jobs.
systemctl list-units			Show the status of all loaded and active systemd units.

To start the service, all you have to do is use the start flag with the systemctl command

sudo systemctl start <service_name>

To stop the service, you use the stop flag with the systemctl command

sudo systemctl stop <service_name>

Check the status of the service

sudo systemctl status <service_name>

Managing Services

systemd can control components that run after boot and also maintain components indefinitely. These tasks are known as units, and each unit has a corresponding unit file. Units might concern mounting storage devices (.mount), configuring hardware (.device), sockets (.socket), or managing services (.service).

Enabling service referes to start the service automatically at the system boot.

sudo systemctl enable <service_name>

Prevent the service from auto starting at boot

sudo systemctl disable <service_name>

Each unit has a corresponding unit file. These unit files are usually located in the following directories:

  • The /lib/systemd/system directory holds unit files that are provided by the system or are supplied by installed packages. This directory is also a symlink to /usr/lib/systemd/user/ directory.
  • The /etc/systemd/system directory stores unit files that are user-provided.

Managing Service Example: Bluetooth

Check if Bluetooth is installed:

sudo systemctl status bluetooth

Enable Bluetooth at Startup: If it’s only starting manually and not on boot, you can enable it at startup:

sudo systemctl enable bluetooth

Run the following commands to start the Bluetooth daemon:

sudo systemctl start bluetooth

Restart the Bluetooth Service:

sudo systemctl restart bluetooth

Check Logs for Errors relating to bluetooth service:

journalctl -xe | grep bluetooth

Use the bluetoothctl command-line tool to further troubleshoot Bluetooth device activation:

bluetoothctl