[systemd-devel] systemd - how to run system service by user target

Lennart Poettering lennart at poettering.net
Wed Oct 19 19:31:40 UTC 2016

On Wed, 19.10.16 12:46, Kamil Jońca (kjonca at o2.pl) wrote:

> Assume we have openvpn.service.
> This service neccessary only when I want to connect to my work from
> home.
> Is it possible to make user target which will be automatically run this
> service?

Whenever a user logs in it will get a per-user slice unit
started. When the user logs out, the slice unit is removed. You could
make sure that your service is pulled in by this slice when the slice
is started (and hence at login) and stopped whenever the slice is
stopped (i.e. at last logout). There's no particularly nice scheme for
that in place, but if you have well-established UIDs, it would be as
easy as dropping in a symlink
pointing to your main service file. Then, inside that file, add
dependencies back to the slice, i.e. something like

I hope you get the idea of what I am suggesting here...


Lennart Poettering, Red Hat

More information about the systemd-devel mailing list