[systemd-devel] Launching a unit in response to a D-Bus signal

Mirco Tischler mt-ml at gmx.de
Mon Oct 1 15:53:00 PDT 2012


2012/10/2 Kok, Auke-jan H <auke-jan.h.kok at intel.com>:
> On Mon, Oct 1, 2012 at 4:58 AM, Matthew Booth <mbooth at redhat.com> wrote:
>> I have a requirement to restart squid whenever the VPN goes up or down[1].
>> Reading around, it seems that the way to do this would be in response to the
>> relevant D-Bus signal, which seems to be this one:
>>
>> signal sender=:1.6 -> dest=(null destination) serial=269
>> path=/org/freedesktop/NetworkManager/ActiveConnection/2;
>> interface=org.freedesktop.NetworkManager.VPN.Connection;
>> member=VpnStateChanged
>>
>> I expected that systemd would allow me to do this, but as far as I can tell
>> it doesn't (I'm using F17). I can obviously write my own daemon to do this,
>> but it seems to me that a daemon just for this would be a waste. I think
>> this sounds like a good fit for systemd. Is it anything anybody's looked at?
>
> The problem with listening on a specific DBus message is that it
> requires you to implement much more of DBus than systemd internally
> can. I'm not sure it's a good idea to put something that complex into
> systemd.
>
> Your alternatives are to write a simple DBus frontend, or perhaps a
> Network Manager plugin (if there is such a thing, I know connman has
> the concept of plugins).
>
> You can certainly socket activate a dummy service that doesn't
> actually listen on DBus but instead executes `systemctl restart
> squid.service` based on the BusName only. Systemd will likely however
> not appreciate the unhandled socket, but it may be worth a try.
>
> Auke
Systemd isn't really the right place to do network related stuff, imo.
Such things are better dealt with in the network connection manager,
where the information is already available.
NetworkManager has a mechanism to execute custom scripts in
/etc/NetworkManager/dispatcher.d on network events. For details take a
look at the man page, support for explicit actions on vpn-up/down is
mentioned there.

Mirco


More information about the systemd-devel mailing list