If you want something to run periodically, you should use a SystemD timer unit. Having a service unit that keeps restarting is not a good idea because basically you have your system always in degraded mode (one or more services failed to remain up).
More details can be found in this Stack Overflow answer, in the Arch Linux wiki about SystemD timers and in the man pages for systemd.timer
, but the gist of it is like this:
1. Setup the check service
/etc/systemd/system/checkwifi.service
:
[Unit]
Description=...
[Service]
Type=oneshot
ExecSTart=/usr/bin/checkWiFi
2. Setup the timer that starts the check WiFi occasionally
/etc/systemd/system/checkwifi.timer
:
[Unit]
Description=Timer for checkWifi
After=conWlan0.service
[Timer]
OnActiveSec=120
[Install]
WantedBy=timers.target
3. Enable and start the timer unit
systemctl enable --now checkwifi.timer
Note that when starting the timer, if the conWlan0.service
hasn't started yet, systemctl
would block and wait for the timer prerequirements to be fulfilled.