Skip to content

Instantly share code, notes, and snippets.

@mjml
Last active October 12, 2021 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjml/ed26eed51cc33ec54e53b73cc74f88e4 to your computer and use it in GitHub Desktop.
Save mjml/ed26eed51cc33ec54e53b73cc74f88e4 to your computer and use it in GitHub Desktop.
Continuously monitor a systemd service
#!/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