systemd
is not a catch-all. It won't be the solution to every problem, however it does give you a lot of tools to help you solve problems. The usefulness of those tools comes down to how well you can use them.
Let's look at a very basic service file check-time.service
(note that I created this service file by hand, using other service files located in /usr/lib/systemd/system/
as references):
[Unit]
Description=Checks the time every second
[Service]
Type=simple
ExecStart=/usr/bin/check-time.py
The service file belongs in /usr/lib/systemd/system/
or /etc/systemd/system/
to be used by systemd
Line By Line
[*]
The section headers. These just group together directives. You can find references to which directives belong where in the systemd
man pages:
[Unit] section
[Service] section
[Install] section
Description
A free-form string describing the unit. This is intended for use in UIs to show descriptive information along with the unit name. The description should contain a name that means something to the end user. "Apache2 Web Server" is a good example. Bad examples are "high-performance light-weight HTTP server" (too generic) or "Apache2" (too specific and meaningless for people who do not know Apache).
type
Configures the process start-up type for this service unit. One of simple, forking, oneshot, dbus, notify or idle.
If set to simple (the default if neither Type= nor BusName=, but ExecStart= are specified), it is expected that the process configured with ExecStart= is the main process of the service. In this mode, if the process offers functionality to other processes on the system, its communication channels should be installed before the daemon is started up (e.g. sockets set up by systemd, via socket activation), as systemd will immediately proceed starting follow-up units.
ExecStart
Commands with their arguments that are executed when this service is started. The value is split into zero or more command lines according to the rules described below (see section "Command Lines" below).
Summary
This service file would simply run the command /usr/bin/check-time.py
when started. If the command exits then it would be considered "dead", so long as it continues to run it is considered "Active".
How useful is this service file? Well, not very. As it is the only thing it does is allow you to run the python script using systemctl start check-time.service
instead of the normal full path, however there are a wealth of additional options that can be useful.
Useful Options
WantedBy If you want the service to start on boot, set WantedBy=
your default target.
Restart Determines when systemd
should automatically restart a service, such as "always" or "on-failure"
Literally hundreds of other options that include limiting hardware usage, which user to use to execute the process, setting environment variables, setting dependencies, and many more. systemd
is useful for all the additional functionality it provides, not simply because it can wrap things.