[systemd-devel] Packaging systemd user-instance service files

Ahmed S. Darwish darwish.07 at gmail.com
Fri Jul 17 11:38:13 PDT 2015


Hi everyone,

I'm currently transforming a network daemon to become a native
``Type=notify'' systemd service. This daemon uses native PulseAudio
simple APIs for output.

Due to the PulseAudio dependency, the service needs to run under the
user session. Otherwise, all PulseAudio APIs [e.g. pa_simple_new()]
returns a ``Connection Refused'' error. [1]

Given the above, I've built the following service file:

    [Unit]
    Description=AirTunes Synchronous Audio Service   
    [Service]
    Type=notify
    ExecStart=/usr/local/bin/shairport-sync    
    [Install]
    WantedBy=default.target

And the following snippet in the package Makefile.am:

    cp scripts/shairport-sync.service /usr/lib/systemd/user/
    systemctl --user daemon-reload
    systemctl --user enable shairport-sync.service
    systemctl --user start shairport-sync.service

As you can see, the service is properly installed under
``/usr/lib/systemd/user/'' to run under the systemd user instance.

Now the problem is that the Makefile commands above run as root,
and thus all the ``systemctl --user'' commands fail with:

    Failed to get D-Bus connection: Connection refused

So, the question is, can I start ``systemctl --user daemon-reload''
and ``systemctl --user enable'' above in some form while the
Makefile is run from root?

Moreover, could the mechanism do so while also making the service
available upon login for all current _and_ future machine users?

Thanks a lot,
Ahmed S. Darwish
http://darwish.chasingpointers.com/

[1] https://github.com/mikebrady/shairport-sync/blob/master/audio_pulse.c


More information about the systemd-devel mailing list