[systemd-devel] service vs target

Mkrtchyan, Tigran tigran.mkrtchyan at desy.de
Wed Jul 8 09:01:45 UTC 2020


Dear systemd developers,

I failed to get the answer to my question from other sources, so
here I am.

We have a software that consist out of many components. Each component
is a single service, let say A.service, B.service, C.service However,
often you want to be able to start and stop them together. There are
two options that I am aware of: a grouping service of a grouping target.


I have tried both of them and both works.

as service:

# mygroup.service
[Unit]
Description=My handy group as service

[Service]
Type=oneshot
ExecStart=/bin/true
ExecReload=/bin/true
RemainAfterExit=on

[Install]
WantedBy=default.target


as target:

# mygroup.target
[Unit]
Description=My handy group as target

[Install]
WantedBy=default.target

The option with service looks (and sounds) very natural, however feels quite synthetic:

Type=oneshot
ExecStart=/bin/true
ExecReload=/bin/true
RemainAfterExit=on

with corresponding status and deps

   Active: active (exited) since Wed 2020-07-08 09:37:41 CEST; 1min 8s ago
  Process: 2551 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
 Main PID: 2551 (code=exited, status=0/SUCCESS)

$ systemctl list-dependencies mygroup.service
mygroup.service
● ├─mygroup at A.service
● ├─mygroup at B.service
● ├─mygroup at C.service
● ├─system.slice
● └─basic.target
●   ├─firewalld.service
...

The target based solution doesn't have this artificial service, but sounds too
official - *target*.

   Active: active since Wed 2020-07-08 10:30:03 CEST; 6s ago

$ systemctl list-dependencies mygroup.target
mygroup.target
● ├─mygroup at A.service
● ├─mygroup at B.service
● └─mygroup at C.service


What is the best practice of doing this?

Thanks in advance,
   Tigran.


More information about the systemd-devel mailing list