Reputation: 783
Is it possible to tell my unit file to wait for any instance (unknown instance name) of a template unit file?
Something like this: After=template@*.service
Example:
I have this template file ([email protected]):
[Unit]
Description=TemplateFile
After=network.target
[Service]
Type=idle
ExecStart=/bin/sh -c '${JBOSS_HOME}/bin/standalone.sh ${JBOSS_START_OPTS}'
ExecStop=/bin/sh -c '${JBOSS_HOME}/bin/jboss-cli.sh ${JBOSS_STOP_OPTS}'
[Install]
WantedBy=multi-user.target
And i have this unit file (other.service):
[Unit]
Description=Other
After=network.target
#Requires=template@[a-zA-Z0-9]*.service
[Service]
Type=idle
Environment=DISPLAY=:0
ExecStart=/usr/bin/gedit
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
I want the other.service unit only to run when at least 1 instance of [email protected] is running
Upvotes: 5
Views: 1126
Reputation: 6948
Have a look at the answer from Lennart Poettering himself
Uh, this conflicts with the entire of systemd so far: we only load referenced units, and for that we need to first know the ultimate name for a unit and then go and find a backing unit file for it. Globbing always turns around these things: we first need to know all available units, to then determine the matching subset of it.
Also, how is this even going to work for instances (which appears to be the desired usecase here): they can be (and usually are) created ad-hoc, that's kinda their main feature: there has to be no record of [email protected] until that unit is started, and only then we'll look for a unit file for it, and will likely find [email protected]. But a wildcard dependency, in particular one that pulls in and actively instantiates other units the way Requires= does it, how can it be generic? I mean, if a unit requires [email protected], what should this actually do? what should it fill into ""? The * after all could be anything, and that's a ridiculous large set... if we'd start every possible instance of a unit when another unit is pulled in, that would make really no sense...
Anyway, I am pretty sure what you are looking for is PartOf/ConsistsOf= which permits you to set up the dependency from the other side. Moreover there are .wants/ and .requires/ symlinks which permit to add requires/wants deps to existing unit, from data stored in other units. I think that these concepts are much better solutions to your specific usecase.
I am sorry, but this request is semantically very broken. Closing this, I hope that makes sense. Sorry!
Upvotes: 0
Reputation: 629
You have to make the instantiated unit part of a custom target.. then require the target in other.service.
Upvotes: 1