[systemd-devel] Creating units using D-Bus
Lennart Poettering
lennart at poettering.net
Tue Jun 9 15:21:12 PDT 2015
On Tue, 09.06.15 19:33, Jakub Skořepa (jakub at skorepa.info) wrote:
> Hello,
> My name is Jakub Skořepa and I'm working on Cockpit UI for Systemd
> Timers.
>
> For that I need to create and modify systemd unit files. Cockpit uses D
> -Bus for everything so I need D-Bus API for that. I think that it would
> be beneficial if systemd was able to create unit files on-the-fly using
> through D-Bus method call.
You can do that already, in the concept of "transient" units. However,
these units are not persistent, they are stored in /run and go away on
reboots. Google for the StartTransientUnit() bus call for details.
I think it would be a good idea to also allow to create persisent
units in a similar way eventually. However, that's not as obvious and
easy as it sounds, it starts from the question where to store those
units. Cron-like semantics would suggest somewhere below /var, but
that means they aren't available at early boot, and we'd have to
reload the configuration and requeue all jobs when /var appears. Which
means we'd have to put them in /etc instead, which however is
suboptimal for many usecases....
I think I'd be willing to merge a patch that adds adds a new bus call
CreatePersistentUnit() that works like StartTransientUnit() except
that it only creates but not starts a unit, and that it stores the
unit in /etc. (Note: the only reason StartTransientUnit() not only
creates but also starts a unit is because the unit would otherwise be
GC'ed away immediately and not be reconstructable after that...)
> I plan creating simple server for doing this task but long-term it woul
> d be better if systemd was capable of doing this.
>
> I propose methods with following signatures:
>
> # CreateUnit:
> # ModifyUnit: (same signature)
> # CreateUnits:
> # ModifyUnits: (same signature as CreateUnits)
Note that StartTransientUnits() already allows creating multiple
units, with appropriate properties, and any such new call should be
modelled after that, should it cover persistent units.
Also, we have the SetProperties() call already for on the Unit object
which allows altering any property during runtime, either persisently
in /etc or transiently in /run. Hence ModifyUnits is unnecessary.
Lennart
--
Lennart Poettering, Red Hat
More information about the systemd-devel
mailing list