[systemd-devel] service vs target

Reindl Harald h.reindl at thelounge.net
Wed Jul 8 10:01:12 UTC 2020



Am 08.07.20 um 11:01 schrieb Mkrtchyan, Tigran:
> 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.
> 
> 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?

targets

[root at srv-rhsoft:~]$ systemctl list-dependencies vmware-guest.target
vmware-guest.target
● ├─guest-arrakis.service
● ├─guest-esxi.service
● ├─guest-testserver.service
● ├─network-up.service
● ├─vmware-modules.service
● ├─vmware-vmnet.service
● ├─vmware.service
● └─vmware.target
●   ├─vmware-authentication.service
●   ├─vmware-modules.service
●   └─vmware-vmnet.service

--------------------------------------

[root at srv-rhsoft:~]$ cat /etc/systemd/system/vmware.target
[Unit]
Description=VMware Service Group
Requires=vmware-modules.service vmware-vmnet.service
Wants=vmware-authentication.service

[Install]
WantedBy=multi-user.target

--------------------------------------

[root at srv-rhsoft:~]$ cat /etc/systemd/system/vmware-guest.target
[Unit]
Description=VMware Guest Group
After=vmware.service vmware-modules.service vmware.target
vmware-vmnet.service network-up.service
Requires=vmware.service vmware-modules.service vmware.target
vmware-vmnet.service
Wants=network-up.service
Wants=guest-arrakis.service
Wants=guest-testserver.service
Wants=guest-esxi.service

[Install]
WantedBy=multi-user.target

--------------------------------------

[root at srv-rhsoft:~]$ cat /etc/systemd/system/guest-esxi.service
[Unit]
Description=VMware-Guest ESXi
PartOf=vmware-guest.target
Requisite=vmware.service
After=vmware-vmnet.service network-up.service
Wants=network-up.service

[Service]
Type=oneshot
RemainAfterExit=yes
Nice=19
IOSchedulingClass=idle
User=vmware
Group=vmware
ExecStart=/usr/bin/vmrun -T ws start
'/mnt/data/fileserver/vmware/esx/esx1.vmx' nogui
ExecReload=-/usr/bin/vmrun -T ws reset
'/mnt/data/fileserver/vmware/esx/esx1.vmx' nogui soft
ExecStop=-/usr/bin/vmrun -T ws stop
'/mnt/data/fileserver/vmware/esx/esx1.vmx' nogui soft
ExecStop=-/usr/bin/sleep 5
TimeoutSec=300
SuccessExitStatus=255

ProtectSystem=full
CapabilityBoundingSet=~CAP_AUDIT_CONTROL CAP_AUDIT_WRITE CAP_SYS_ADMIN
CAP_SYS_BOOT CAP_SYS_PTRACE
IPAddressDeny=any
IPAddressAllow=localhost

PermissionsStartOnly=true
ExecStartPre=-/usr/bin/chgrp vmware /dev/vmnet8
ExecStartPre=-/usr/bin/chmod g+rw /dev/vmnet8

[Install]
WantedBy=vmware-guest.target

--------------------------------------


More information about the systemd-devel mailing list