You are not logged in.

#1 2014-10-02 15:13:47

jlesquembre
Member
Registered: 2012-11-10
Posts: 5

Systemd service, make it response to network changes

I'm using netctl and I'm trying to make my own service. The idea is that my service is restarted if I do a

systemctl restart netctl@net0

or if I unplug and plug again the network cable with the service netctl-ifplugd@net0 enabled. First case is easy, but I don't find a solution for both cases, any suggestions?

Offline

#2 2014-10-02 20:37:07

teckk
Member
Registered: 2013-02-21
Posts: 519

Re: Systemd service, make it response to network changes

I don't understand what you are trying to do.

I'm using netctl

https://wiki.archlinux.org/index.php/netctl

Do you want

netctl stop mynetwork
netctl start mynetwork

Offline

#3 2014-10-03 12:44:35

jlesquembre
Member
Registered: 2012-11-10
Posts: 5

Re: Systemd service, make it response to network changes

I wrote service like this:

[Unit]
Description=Service on interface %I
Wants=docker.service

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/lib/project/my_script.sh start %I
ExecStop=/usr/lib/project/my_script.sh stop %I

[Install]
WantedBy=multi-user.target

What I want is restart this service if I do a restart of the network, with 'netctl restart mynetwork' or automatically via the 'netctl-ifplugd@mynetwork' service. Ideally my service restart would be independent from netctl and only dependent of the network interface.

Offline

#4 2014-10-03 15:26:09

firecat53
Member
From: Lake Stevens, WA, USA
Registered: 2007-05-14
Posts: 1,542
Website

Re: Systemd service, make it response to network changes

Try changing your service under [Unit] to:

[Unit]
Description=Service on interface %I
Wants=docker.service
PartOf=netctl-ifplugd@mynetwork.service

See 'man systemd.unit' for more info on the PartOf directive. I _think_ that's what you might be trying to do smile

Scott

Last edited by firecat53 (2014-10-03 15:26:32)

Offline

#5 2014-10-03 21:19:25

jlesquembre
Member
Registered: 2012-11-10
Posts: 5

Re: Systemd service, make it response to network changes

@firecat53, thanks for the info about the PartOf directive, I didn't know it and is really useful. But doesn't help in this case, service netctl-ifplugd watchs the interface for changes, but never restart itself. If I unplug and plug the network cable, the network is restarted, but not the service itself, and my service is not restarted.

Offline

Board footer

Powered by FluxBB