7

I have a custom upstart job that triggers a series of services:

/etc/init/auto-gateway.conf:

description "Auto-GateWay"
author      "g4gvideo@gmail.com"

emits gw-is-up
emits gw-is-down

start on (net-device-up or net-device-down)

task

script
if route | grep -q "default"; then
    initctl emit -n gw-is-up
else
    initctl emit -n gw-is-down
fi

end script

This works works extremely well on laptops that frequently disconnect and connect from networks, or when they sleep & wakeup. It also works on my servers when the network changes.

I am trying to convert this simple upstart job to systemd. My first attempt is:

/etc/systemd/system/auto-gateway.service:

[Unit]
Description=Auto-Gateway service
After=network-online.target

[Service]
ExecStart=/usr/sbin/auto-gateway
KillMode=process
Restart=always
Type=forking
TimeoutStartSec=infinity

[Install]
WantedBy=multi-user.target

/usr/sbin/auto-gateway:

#!/bin/bash

while true; do

if route | grep "default"; then
    start some services (if not running)
else
    stop some services (if running)
fi

sleep 30
done >/dev/null

I find this to be a poor substitute to the upstart version. I dislike the fixed timer, and hard coding the secondary services into auto-gateway.

Is there any way systemd can monitor netdev instead?

Thanks

closed as off-topic by WinEunuuchs2Unix, David Foerster, Charles Green, Eric Carvalho, user364819 Jul 3 '17 at 20:41

  • This question does not appear to be about Ubuntu within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • have you found solution? – Kostanos Oct 18 '16 at 12:53
  • No. I am so disappointed in systemd - it is overly complicated and basically is systemV on steroids. Upstart is much easier and simpler to use. The only real way to do do this is to write custom scripts in /etc/network/if-up.d/ /etc/network/if-down.d/ and forget about using systemd. Canonical has made a poor desision to switch to systemd (in my opinion :). Note to developers: systemd is not suable for laptops and non-enterprise deployments! – C4g Video Nov 10 '16 at 21:15
  • You may try systemd-mailing list or upstart mailing list for help. – Khurshid Alam Jan 31 '17 at 15:13
  • 4
    I'm voting to close this question as off-topic because user hasn't signed on in over 6 months and never responded to last comment after his last sign on also > 6 months old. This can be deemed "abandoned question" as per this rule: meta.askubuntu.com/questions/1843/… – WinEunuuchs2Unix Jul 2 '17 at 21:35