Skip to content

This document is a WORK IN PROGRESS.
This is just a quick personal cheat sheet: treat its contents with caution!


SystemD

SystemD is a suite of basic building blocks for a Linux system. It provides a system and service manager that runs as PID 1 and starts the rest of the system.

Reference(s)

Table of contents

TODO


Services

Basic services control

  • Start the service_name service:

    # systemctl start service_name
    

  • Stop the service_name service:

    # systemctl stop service_name
    

  • Restart the service_name service:

    # systemctl restart service_name
    

  • Reload service_name configuration without stopping the service_name service:

    # systemctl reload service_name
    

  • Check the service_name service status:

    # systemctl status service_name
    

  • Enable the service_name service on system boot:

    # systemctl enable service_name
    

  • Disable the service_name service on system boot:

    # systemctl disable service_name
    

  • Check if the service_name service is enable or disable on system boot:

    # systemctl is-enabled service_name
    

Inspect services

  • Check if any SystemD services have entered in a failed state:
    $ systemctl --failed
    

Override services

Let's you want the ntpd service to automatically restart if a failure happens. You could "manually" edit the associated .service file (/usr/lib/systemd/system/ntpd.service), but this file could be overritten after a system update or package install. This is where the systemctl edit command is interresting, it will create an associated override.conf file that will always apply:

  • Edit the override file (e.g. of ntpd.service, located in /etc/systemd/system/ntpd.service.d/override.conf and not in /usr/lib/systemd/system/ntpd.service) :

    $ EDITOR=vi systemctl edit ntpd.service
      + > [Service]
      + > Restart=on-failure
    

  • Check the syntax e.g. of /usr/lib/systemd/system/ntpd.service and /etc/systemd/system/ntpd.service.d/override.conf:

    $ systemd-analyze verify ntpd.service
    

  • Print the full ntpd service (ntpd.service and ntpd.servce.d/override.conf) :

    $ systemctl cat ntpd.service
        > # /usr/lib/systemd/system/ntpd.service
        > [Unit]
        > Description=Network Time Service
        > After=syslog.target ntpdate.service sntp.service
        >
        > [Service]
        > Type=forking
        > EnvironmentFile=-/etc/sysconfig/ntpd
        > ExecStart=/usr/sbin/ntpd -u ntp:ntp $OPTIONS
        > PrivateTmp=true
        >
        > [Install]
        > WantedBy=multi-user.target
        >
        > # /etc/systemd/system/ntpd.service.d/override.conf
        > [Service]
        > Restart=on-failure
    

Analyze services

Reference(s)
  • Create an SVG graphic detailing which system services have been started at what time, highlighting the time they spent on initialization:
    $ systemd-analyze plot > systemd_analyze_plot.svg
    

Run levels

TODO


Tips and tricks

  • Start system in a non-graphical mode:

    $ systemctl get-default
        > graphical.target
    
    $ sudo systemctl set-default multi-user.target
    

  • Check SystemD journal for a service:

    $ sudo journalctl -xeu service-name
    

    -x, --catalog: Augment log lines with explanation texts from the message catalog. This will add explanatory help texts to log messages in the output where this is available. These short help texts will explain the context of an error or log event, possible solutions, as well as pointers to support forums, developer documentation, and any other relevant manuals.

    -e, --pager-end Immediately jump to the end of the journal inside the implied pager tool.

    -u, --unit=UNIT|PATTERN Show messages for the specified systemd unit UNIT (such as a service unit), or for any of the units matched by PATTERN.


If this cheat sheet has been useful to you, then please consider leaving a star here.