init is the first process started by the Linux kernel once booted. It has the process ID (PID) of 1. This init process is in charge of starting services on boot and shutting them down when turning the computer off. systemd is the preferred init system of modern Linux distributions that has succeeded SysVinit. [1][2]


File Locations

systemd unit files can be created and used in any of these locations [3]:

  • /usr/lib/systemd/system/ = Global systemd unit files installed by the system package manager.

  • /run/systemd/system/ = Unit files that were created automatically by a program.

  • /etc/systemd/system/ = User-created unit files. These override all other locations if a unit file exists with the same name.

  • ~/.config/systemd/user/ = User-created unit files that are managed locally by a user. These services only run while the user is logged in. These are managed with the command systemctl --user instead of the typical systemctl command.

When adding new unit files, it is required to run this command to update the systemd cache about available unit files [4]:

$ sudo systemctl daemon-reload

Creating a Unit File

All unit files are ini configuration files that use this layout:




Configuration options for unit files:

  • Run a system unit during a normal boot.

  • Run a user unit during login.

  • Log standard output and/or standard error of a service to a file.

  • Create a service that runs exactly once.

    ExecStart=/bin/systemctl --no-reload disable %n
  • Run the unit file if the file or directory does not exist.

  • Do not timeout while starting a service.

  • Start a service after a specified amount of time.

    ExecStartPre=/bin/sleep 0.5
  • Automatically restart a service if it fails. [5]

  • Run two or more commands. systemd will run one command at a time starting from top to bottom.

    ExecStart=/bin/sh -c "echo foo"
    ExecStart=/bin/sh -c "echo bar"
  • Start a unit after the networking service is online. If there is no network interface on the computer, then systemd will consider the networking services to be online.

    • Depending on the networking service used, enable it to wait to be online. [6]

      $ sudo systemctl enable NetworkManager-wait-online.service
      $ sudo systemctl enable systemd-networkd-wait-online.service
  • Configure environment variables in the systemd unit file or source them from an external file. [8]

    $ cat /app/env

Preset Files

System packages can define if a unit should be enabled or disabled by default. [7]

  • Create a file called /usr/lib/systemd/system-preset/<UNIT>.<UNIT_TYPE>.

  • Edit the file with the contents of enable <UNIT>.<UNIT_TYPE> or disable <UNIT.<UNIT_TYPE>.

Enable Services on Boot

Enable a system service to start on boot. [9]

  • Automatically:

    $ sudo systemctl enable <UNIT>
  • Manually:

    $ sudo ln -s /usr/lib/systemd/system/<UNIT>.service /etc/systemd/system/<UNIT>.service

Enable a user service to start when the login. [10]

  • Automatically:

    $ systemctl --user enable <UNIT>
  • Manually:

    $ ln -s ~/.config/systemd/user/<UNIT>.service ~/.config/systemd/user/<UNIT>.service



  1. “What is an init system?” Fedora Magazine. October 31, 2015. Accessed May 11, 2023.

  2. “init.” ArchWiki. March 12, 2023. Accessed May 11, 2023.

  3. “Understanding Systemd Units and Unit Files.” DigitalOcean Tutorials. February 17, 2015. Accessed May 11, 2023.

  4. “Where do I put my systemd unit file?” Unix & Linux Stack Exchange. March 10, 2023. Accessed May 11, 2023.

  5. “Auto-restart a crashed service in systemd.” Mattias Geniar. January 13, 2020. Accessed May 11, 2023.

  6. “Network Configuration Synchronization Points.” 2022. Accessed May 11, 2023.

  7. “systemd.preset.” systemd. Accessed May 16, 2023.

  8. “Using environment variables in systemd units.” Flatcar Container Linux. Accessed August 29, 2023.

  9. “Use systemd to Start a Linux Service at Boot.” Linode Docs. March 9, 2023. Accessed September 8, 2023.

  10. “Start a systemd user service at boot.” Super User. August 14, 2023. Accessed September 8, 2023.