Last active
October 12, 2021 19:42
-
-
Save mjml/ed26eed51cc33ec54e53b73cc74f88e4 to your computer and use it in GitHub Desktop.
Continuously monitor a systemd service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
cd /root/.maint | |
# Remove any pre-existing pipe if one exists | |
if [[ -e jcpipe ]]; then | |
rm -f jcpipe | |
fi | |
mkfifo jcpipe | |
# Use this command to feed the pipe with data continuously | |
/usr/bin/journalctl -x -b -f -u hostapd >jcpipe & | |
# Now read lines from the pipe forever; if we find the error message, take action. | |
while read line; do | |
if [[ "$line" =~ "Could not add STA to kernel driver" ]]; then | |
# wait 3s then restart | |
sleep 3 | |
/usr/bin/systemctl restart hostapd | |
fi | |
done < jcpipe | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment