You are not logged in.

#1 2017-10-04 09:29:56

zorggy
Member
Registered: 2013-05-30
Posts: 26

[Solved] Targets in systemd

Hello,

I would like to create a target to gather several units, so that it's possible to start and stop the set in once. This target should not be a default one, such as graphical.target, and it should start in the boot process after multi-user.target. The units should start sequentially (unit1, then unit2).
Here are the config files (simplified):

/etc/systemd/system/test_target.target:

[Unit]
Description=test_target
AllowIsolate=false
Requisite=multi-user.target
After=multi-user.target

[Install]
WantedBy=multi-user.target

/etc/systemd/system/test_service.service:

[Unit]
Description=test_service
BindsTo=test_target.target

[Service]
ExecStart=/usr/bin/true
ExecStop=/usr/bin/false
SuccessExitStatus=1
Type=oneshot
RemainAfterExit=true

[Install]
WantedBy=test_target.target

/etc/systemd/system/data-test_mount.mount:

[Unit]
Description=data-test_mount
Conflicts=umount.target
BindsTo=test_target.target
After=test_service.service

[Mount]
What=/dev/sda
Where=/data/test_mount
TimeoutSec=10s

[Install]
WantedBy=test_target.target

To refresh systemd config:

systemctl daemon-reload

To enable the target:

systemctl enable test_target.target

Starting the target or rebooting does not work as intended, units are not started or stopped.
Where do I make a mistake? Are my config files clean? What would you change?

Last edited by zorggy (2017-10-04 10:19:20)

Offline

#2 2017-10-04 09:50:18

progandy
Member
Registered: 2012-05-17
Posts: 5,322

Re: [Solved] Targets in systemd

I think you have to enable all the services and mounts, too. This snippet defines that the unit will be linked to test_target when it is enabled.

[Install]
WantedBy=test_target.target

Last edited by progandy (2017-10-04 09:51:49)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' | alias ENGLISH='LANG=C.UTF-8 ' |

Offline

#3 2017-10-04 10:17:59

zorggy
Member
Registered: 2013-05-30
Posts: 26

Re: [Solved] Targets in systemd

Hello Propagandy,

You are perfectly right, I was missing one of the services in the real life. Thank you very much!

Offline

Board footer

Powered by FluxBB