[systemd-devel] Starting/stopping service on net connection
Dan Tihelka
dtihelka at gmail.com
Sun Oct 14 07:15:32 PDT 2012
Hallo,
just a short question, sorry if it seems "stupid", I am just curious. And
google does not provide satisfactory answers (or I didn't ask the right
question)
So:
is there a robust and reliable way of starting/stopping a service when a net
connection is established/lost? And I mean also the case where a cable is
disconnected (or wifi signal lost), which should be detected by NetworkManager
(or an alternative daemon).
I have looked at systemd.special man and there are basically two targets, none
of them doing what I want to:
network.target - in LSB $network it is referred to "low level networking
(ethernet card; may imply PCMCIA running)"
nss-lookup.target - this I understand as sipmly "a network-managing daemon is
started", also LSB seems to refer it as "daemons which may provide hostname
resolution (if present) are running"
Another option is to wait for a dbus signal broadcasted from a network
management daemon, if there is such (the signal). Although it is rather
network management system dependent, it could be OK as well.
Also, there is a possibility to check the existence of IP address in loop, but
I am not sure if it would work *). To use socket/based activation is also not
very useful for services being "clients" connecting to a remote server.
Well, to make it clear, I do not need it for any particular program now, I
just want to know if it is possible with systemd or not. Because there are two
worlds meeting - network management service which is responsible for working
network connection, and init responsible for starting/stopping services under
various conditions.
Thank you for your answers
Dan
*)
I mean a loop doing a regular check, and if address is assigned to an
interface an service could be started by systemctl. Or more generally. a dbus
signal could be broadcasted, allowing more services be started by it.
Similarly, another signal could be sent when address disappears, or "reset"
request when an interface is changed ... But it may require some amount of
(non trivial?) shell scripting ...
More information about the systemd-devel
mailing list