Table of Contents
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. 
systemd unit files can be created and used in any of these locations :
/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 --userinstead of the typical
When adding new unit files, it is required to run this command to update the systemd cache about available unit files :
$ sudo systemctl daemon-reload
All unit files are ini configuration files that use this layout:
[Unit] Description=<DESCRIPTION_ABOUT_UNIT> [<UNIT_TYPE>] <UNIT_CONFIG_KEY>=<UNIT_CONFIG_VALUE> [Install] WantedBy=<SYSTEMD_TARGET>
Configuration options for unit files:
Run a unit during a normal boot.
Log standard output and/or standard error of a service to a file.
[Service] StandardOutput=<PATH_TO_FILE> StandardError=<PATH_TO_FILE>
Create a service that runs exactly once.
[Service] Type=oneshot ExecStart=<PATH_TO_EXECTUABLE> 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.
[Service] ExecStartPre=/bin/sleep 0.5 ExecStart=/usr/bin/foobar
Automatically restart a service if it fails. 
[Service] ExecStart=/usr/bin/foobar Restart=on-failure RestartSec=0.1s
Run two or more commands. systemd will run one command at a time starting from top to bottom.
[Service] Type=oneshot ExecStart=/bin/sh -c "echo foo" ExecStart=/bin/sh -c "echo bar" RemainAfterExit=yes TimeoutSec=0
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.
[Unit] After=network-online.target Wants=network-online.target
Depending on the networking service used, enable it to wait to be online. 
$ sudo systemctl enable NetworkManager-wait-online.service
$ sudo systemctl enable systemd-networkd-wait-online.service
“What is an init system?” Fedora Magazine. October 31, 2015. Accessed May 11, 2023. https://fedoramagazine.org/what-is-an-init-system/
“init.” ArchWiki. March 12, 2023. Accessed May 11, 2023. https://wiki.archlinux.org/title/init
“Understanding Systemd Units and Unit Files.” DigitalOcean Tutorials. February 17, 2015. Accessed May 11, 2023. https://www.digitalocean.com/community/tutorials/understanding-systemd-units-and-unit-files
“Where do I put my systemd unit file?” Unix & Linux Stack Exchange. March 10, 2023. Accessed May 11, 2023. https://unix.stackexchange.com/questions/224992/where-do-i-put-my-systemd-unit-file
“Auto-restart a crashed service in systemd.” Mattias Geniar. January 13, 2020. Accessed May 11, 2023. https://ma.ttias.be/auto-restart-crashed-service-systemd/
“Network Configuration Synchronization Points.” systemd.io. 2022. Accessed May 11, 2023. https://systemd.io/NETWORK_ONLINE/
“systemd.preset.” systemd. Accessed May 16, 2023. https://www.freedesktop.org/software/systemd/man/systemd.preset.html