I have a device (e.g. raspberry) running a minimal version of linux built with YOCTO and with not network manager available. At a given time a network configuration may be present in the file /home/root/wpa.conf, but it is not guaranteed that the corresponding wifi network can be detected when the configuration is present (the device can move). I want to write a service that constantly tries to connect to the wifi and, retries when it fails. The problem is that wpa_supplicant does not exit when the SSID is not found.
This is my service:
[Unit] After=network.target [Service] ExecStart=/home/root/connect_to_wifi.sh Restart=always # this would be useful if wpa_supplicant exited on fail StandardOutput=file:/home/root/connect_to_wifi.log StandardError=file:/home/root/connect_to_wifi_error.log [Install] WantedBy=default.target
This is the script:
#!/bin/bash ifconfig wlan0 up udhcpc -i wlan0 -b wpa_supplicant -i wlan0 -c /home/root/wpa.conf
I omitted the -B in wpa_supplicant because the service would exit after running the command, killing wpa_supplicant. I tried to set type=forking in the service but it didn't work. However, I don't think this is the problem in this case.
How can i modify my service and script in order to continuously attempt to connect?