[systemd-devel] "libsystemdexec/systemd-run --exec-from-unit"

Colin Walters walters at verbum.org
Sun Jan 29 06:56:35 UTC 2017


Hey so, this is is a half-baked thought, but here goes:

One problem I've hit when trying to use systemd unit file
features is that they only work when executed by systemd.
Let's take the example of User=, but it applies to tons of
other ones too.

Wait you ask - your service runs under systemd, why
do you care about running it not under systemd?  The
main case I hit is I often want to run my service
under a debugger.

If I just do gdb /usr/lib/myservice ... it will run as root.
Now of course, I could runuser myservice gdb --args /usr/lib/myservice.
But as a unit file gains more features, from WorkingDirectory
to ProtectSystem=, I find myself wanting something like:

systemd-run --exec-from-unit myservice.service /path/to/myservice/src/myservice

Basically exec an uninstalled copy from the builddir.  Or alternatively,
do a `sudo make install` type thing and:

systemd-run --exec-from-unit myservice.service --execstart-args gdb --args

Has anyone else hit this?  Am I missing something obvious?

Taking this out a little bit, I could imagine having the systemd unit  -> execprep
as a shared library.  This would make it easier to use inside daemon
code itself.  This solves a few scenarios like having the service itself
spawn helper processes that don't quite fit into the template model.




More information about the systemd-devel mailing list