For minimum maintenance (read: maximum laziness) I also want to have the hostapd.service unit restarted when something undesired happens to it, so I have another drop-in snippet:

/etc/systemd/system/hostapd.service.d/restart.conf

[Service]
Restart=always
RestartSec=15

This seems to work all right when I e.g. kill the hostapd process.

However today I woke up to find my wireless network gone.The system itself was fine. It was just that the wireless USB dongle apparently became disconnected for a short time, and then was re-attached, as far as dmesg told me.On device loss systemd seemed to have stopped hostapd.service as per the BindsTo= directive, however it wasn't restarted automatically.

Now, "man systemd.service" tells me,

When the death of the process is a result of systemd operation (e.g. service stop or restart), the service will not be restarted.

Therefore I assume hostapd.service was not restarted because it was stopped by systemd itself.

So, my question is:Is it possible, with the features systemd brings to the table, to have a service that was terminated due to device loss be restarted automatically once said device becomes available again?

I ask this because I imagine many people run wireless access points or generally have similar requirements for a systemd service that depend on devices being available.Therefore, as a not-that-exotic-at-all real-world scenario, systemd hopefully provides for things like this, and I just haven't found out how to set it up properly.

I have tried it without the BindsTo= directive, but it doesn't do any good because hostapd cannot handle it when its wireless device is lost and re-attached. So I need hostapd to be restarted when the device reappears.

I would hate to have to write an udev trigger or something the like, especially seeing that systemd has the capability to watch for devices built right into it (otherwise After=xyz.device and BindsTo= wouldn't work at all, would they?)

Re: [SOLVED] BindsTo: Restart a service after device rediscovery?

Keep in mind that if the wireless interface can go away and come back by itself then it can also go away and not come back. I would focus on addressing this.

Granted, the hardware situation could arguably be better.

Still it would be awesome if the hostapd service would be restarted automatically if e.g. somebody stepped on the USB cable, or generally if the device was detached by accident for a short time.This would definitely beat having to power cycle the wireless access point for lack of SSH knowledge/access.

Re: [SOLVED] BindsTo: Restart a service after device rediscovery?

Trilby wrote:

(...) It sounds like you just don't want the BindsTo behavior, so remove that line: (...)

Tried that, did not work:

eomanis wrote:

I have tried it without the BindsTo= directive, but it doesn't do any good because hostapd cannot handle it when its wireless device is lost and re-attached. So I need hostapd to be restarted when the device reappears.