0

I have the following service.

/etc/systemd/system/detectwifi.service

[Unit]
Description=wifi detect automation
Requires=wpa_supplicant.service
After=wpa_supplicant.service

[Service]
Type=simple
ExecStart=/sbin/wpa_cli -a /home/pi/test.sh -B
Restart=always
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

Then I started the service, I have seen that the command wpa_cli -a /home/pi/test.sh -B is running. Then killed the process and it won't restart again.

May I know the reason why the restart is not working?

Also If I comment the line RemainAfterExit=yes, then the service will start to restart but it keeps on restart continuously even if the process run successfully.

  • You might want to try Type=forking since you start wpa_cli in daemon mode. – Thomas Apr 22 at 10:32
1

A recommedation to keep -B and switch to a readiness protocol that the program does not speak is another example of why one should always take comment-answers with a huge dose of salt.

  • Do not use RemainAfterExit=yes when it is a lie, as here. Your dæmon is not considered running when the process has exited.
  • Do not use -B. The idea of dæmonization is a fallacy in any case, and your process is already running in a dæmon context.

One problem that you will encounter is that systemd does not know that your service should not be run until the relevant wpa_supplicant service has bound its control socket in /run/wpa_supplicant/. There are timing problems here that people just have to bodge around with things restarting continually until the service "takes".

wpa_supplicant does not yet provide a way for its control socket to be passed in as an already open file descriptor, which would allow it to be defined using a systemd socket unit, which the wpa_cli service unit could then be ordered after.

Further reading

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.