I would like to move my old fashioned start/stop/status init script to systemd

It basically does, start:

ifconfig eth0:vip up


ifconfig eth0:vip down


ifconfig  | grep 'eth0:vip'

I have tried to create a systemd service unit:

ExecStart=/path/myscript start
ExecStop=/path/myscript stop

But systemctl status doesn't have any way to detect when eth0:vip goes down with a manual ifconfig eth0:vip down.

What should I do to have my script be compliant to systemd?

  • can you edit your question and add your script?
    – Michael D.
    Mar 3 '17 at 15:33

This unit is compliant. There is no improvement to be made in that sense.

systemd simply does not support defining a custom action for systemctl status foo, unlike the init.d scripts in System V init. systemd can only check for a running daemon (or not, given RemainAfterExit).

systemd does not track units for network status, IP addresses, nor the legacy interface aliases you're using.

You could change your main network configuration system instead, to include the second IP address. You might enjoy having all your network address configuration in the same place :).

systemd-networkd supports running DHCP and static addresses on the same interface. NetworkManager does not, but nowadays you can create a keyfile to create virtual macvlan interfaces as children of the physical one. (In theory this might even allow you to request multiple DHCP addresses :). Do not try to apply configurations from more than one of these configuration systems to the same named interface. If you're already running NetworkManager, it's probably easiest to use that.

Both systemd-network (networkctl) and NetworkManager (e.g. nmcli) will then detect and show if you change their network interfaces yourself.

It may also be possible to configure older config systems[1][2] to create macvlan interfaces. However, from what I remember, they could get quite confused if you mess around with the interfaces behind their backs.

Additional custom pre-up or post-up tasks could be hacked up in most configuration systems if necessary[3], although systemd-networkd does not have any such system built-in. I say "hacked", because the NM system isn't really designed to run scripts written for one specific interface.

  • So systemd may say a service is active, even when the associated ressource is down ... Mar 7 '17 at 15:54
  • It does, but you didn't associate a resource with it! What you mean to say, is that the only type of resource systemd will let you associate with a service, are the processes started for that service. It does not support associating any other type of resource, and does not support associating custom types of resource (equivalent to defining /etc/init.d/foo status).
    – sourcejedi
    Mar 7 '17 at 16:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.