minimal systemd unit

Add them in under /etc/systemd/system/

sudo touch /etc/systemd/system/cool_unit.service
sudo chmod 664 /etc/systemd/system/cool_unit.service
sudo vi /etc/systemd/system/cool_unit.service

[Unit]
Description = A good description

Requires = # This unit also activates these units
Wants = # Optional Requires, adviced to use this
Conflicts = # Starting this unit will kill the other and opposite

[Install]
# Alternative names
Alias= 

# RequiredBy / WantedBy = Same as in Unit, but reverse
WantedBy = multi-user.target

Also= 
# Which other units should be enabled/disabled with this unit 

[Service]
Type = simple

# simple    : starts the service immediately. It is expected that the main process of the service is defined in `ExecStart`
# foking    : considers the service started up once the process forks and the parent has exited.
# oneshot   : similar to `simple`, but it is expected that the process has to exit before systemd starts follow-up units (useful for scripts that do a single job and then exit). You may want to set `RemainAfterExit=yes` as well so that systemd still considers the service as active after the process has exited.
# dbus      : similar to `simple`, but considers the service started up when the main process gains a D-Bus name.
# notify    : similar to `simple`, but considers the service started up only after it sends a special signal to systemd.
# idle      : similar to `simple`, but the actual execution of the service binary is delayed until all jobs are finished.

# User/Group to run as
User = root 
Group = root 

# Command to run
ExecStart= 

# Command to stop
ExecStop= 

# Commannd to run if unit config is changed
ExecReload = 

# Restart config
Restart = on-failure 

# no            : Never
# on-success    : Only on clean exit
# on-failure    : Everything but clean exit
# on-abnormal   : Unclean signal, timeout, watchdog
# on-watchdog   : Only watchdog trigger
# on-abort      : Only Unclean exit signal
# always        : Always

# Assumed active even after exit
RemainAfterExit = False 

Todo:

[] zsh/bash function for adding new systemd files

More examples

https://www.freedesktop.org/software/systemd/man/systemd.service.html https://www.shellhacks.com/systemd-service-file-example/