Skip to content

Instantly share code, notes, and snippets.

@fser
Created April 27, 2016 23:17
Show Gist options
  • Save fser/1d3f04012a89b1094558b280e8752c1e to your computer and use it in GitHub Desktop.
Save fser/1d3f04012a89b1094558b280e8752c1e to your computer and use it in GitHub Desktop.
nagios sensor to check wether services / server needs to be restarted. It depends on checkrestart (from debian-goodies) to list packages which needs to be restarted.
#!/usr/bin/env bash
if [ -e /var/run/reboot-required ]; then
echo "error: need reboot (kernel upgrade)"
exit 2
fi
checkrestart &>/dev/null || { echo 'need checkrestart (apt-get install debian-goodies) to get the actual service list' ; exit 1; }
if [ -e /var/run/reboot-required.pkgs ]; then
echo -n 'error: services need restart ('
checkrestart | grep service | awk '{ service[$2]++; } END { for (s in service) { printf ("%s ", s) } }'
echo ')'
exit 1
fi
echo "ok"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment