I’ve written about half a dozen .service files for the different parts that make up the system I’m working on. It’s useful to be able to start the whole system piecemeal but I’d also like to have a single unit that starts the whole system in one call to systemctl.
What’s the best way to do this?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
You want a target-type unit, with all the service units listed as Wants= dependencies. Then you start it using systemctl start unitname.target. (Make sure not to use systemctl isolate here; that will shut down everything except what’s in your services’ dependency tree, which you presumably don’t want.)
Method 2
Have you tried using PartOf on the sub-units of the target group in addition to Wants in the target? Ex: PartOf=foo.target in foo-sub1.service and Wants=foo-sub1.service foo-sub2.service in foo.target. I just tried this and was able to start and stop all my sub-units just by starting and stopping the target.
PartOf=
Configures dependencies similar to Requires=, but limited to stopping and restarting of units. When systemd stops or restarts the units listed here, the action is propagated to this unit. Note that this is a one-way dependency — changes to this unit do not affect the listed units.
When PartOf=b.service is used on a.service, this dependency will show as ConsistsOf=a.service in property listing of b.service. ConsistsOf= dependency cannot be specified directly.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0