You are not logged in.
Pages: 1
Assume I have a food (the "foo" daemon -- couldn't resist) that occasionally requires access to a running mysql database server.
Can I express this somehow using systemd, so that when I say:
> systemctl start food
systemd will check first whether mysqld is running, and if not, start it?
(This is not about food or mysqld, it's a question about systemd.)
A more complex version of the same question could be bard (the bar daemon) depending on a locally running mail server, without specifying which particular one.
Thanks,
Johannes.
Offline
Isn't this explained in the wiki page and man pages?
Offline
Perhaps I'm not seeing the trees because of all the forest. Any chance you could point me to an example?
Offline
man systemd.unit
Although your requirements are quite ambiguous: "occasionally requires" and "depending on which one" muddy this issue somewhat. I suspect you are looking for Wants.
Offline
Ah! Thank you. I never reached that man page.
So I would have food.service Requires or Wants or BindsTo mysqld.service, and possibly also an After, so I'm sure that by the time food arrives, mysqld is ready. Great!
Add-on: now let's assume that food requires a particular MySQL configuration setting (like, say, binary logs being on). Manually, I would do this:
1. Edit MySQL config file, e.g. using perl -pi, so that the setting is on
2. If MySQL is not running, start it
3. If MySQL is running, restart it
4. Start my actual daemon
So the Wants and Requires and all that lets me elegantly deal with the case where MySQL isn't running yet. But what if it is, and MySQL needs to be restarted? Does systemd somehow support that use case as well, and I (again) didn't find the documentation for it? (If so, I'm very sorry and appreciate all pointers)
Side note: Systemd does not seem to like a "systemd restart xyz" invocation from within another systemd start invocation, so I cannot write the above four steps into a food.service script. (Apparently the "inner" systemctl invocation waits for the previous one to finish before proceeding, i.e. deadlock)
Offline
The "Wants" entries name other services (e.g. other systemd service files) not programs. So you could have a mysql-bin-logs.service and a mysql-no-logs.service (which should then conflict with each other). Food.service would just specify that it wants mysql-bin-logs.
EDIT: in fact you'd probably want to use variables rather than the two different service files - look at dhcpcd@.service for a common example. You could then have mysql@logs or mysql@nologs or something of the sort.
Last edited by Trilby (2014-08-07 22:26:46)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
@trilby: that is so much cleaner! I like it. Thank you.
Offline
Pages: 1