Check which services/processes need restart after update
Esa Karkkainen
ejk at iki.fi
Sat Mar 5 11:29:10 UTC 2016
On Thu, Mar 03, 2016 at 10:07:21PM +0100, Walkenhorst, Benjamin wrote:
> Hello,
Hello,
> Only recently I was happy to discover that Debian has a tool called
> checkrestart that checks which services need to be restarted after
> an update.
> I thought that was very nice and now I am kind of wondering if there
> is something comparable for FreeBSD.
I made a small shell script, which starts the "monitored" services if the
service is not running.
It sends me an email when PID changes, if you don't want that remove or
add a comment to the line which has "diff -u etc" command.
I run this script from cron every five minutes.
Line in /etc/crontab
# grep check_service /etc/crontab
*/5 * * * * root /root/bin/check_services
The script it self, please notice that my email client has wrapped few
lines.
# cat /root/bin/check_services
!/bin/sh
set -u
#set -x
if [ ! -e /var/run/check_services.prev ] ; then
touch /var/run/check_services.prev || exit 1
chown root:wheel /var/run/check_services.prev || exit 1
chmod 0640 /var/run/check_services.prev || exit 1
fi
if [ -e /var/run/check_services.now ] ; then
cp /dev/null /var/run/check_services.now || exit 1
else
touch /var/run/check_services.now || exit 1
chown root:wheel /var/run/check_services.now || exit 1
chmod 0640 /var/run/check_services.now || exit 1
fi
for i in list of services to be monitored
do
service $i status >> /var/run/check_services.now 2>&1
pid="$(tail -1 /var/run/check_services.now|tr -d '.'|awk '{print
$6}')"
if [ -z "${pid}" ] ; then
service "${i}" start
fi
done
unset i
diff -u /var/run/check_services.prev /var/run/check_services.now 2>&1
if cmp -s /var/run/check_services.prev /var/run/check_services.now ;
then
:
else
mv /var/run/check_services.now /var/run/check_services.prev ||
exit 1
fi
exit 0
--
"In the beginning the Universe was created. This has made a lot of
people very angry and been widely regarded as a bad move."
-- Douglas Adams 1952 - 2001
More information about the freebsd-questions
mailing list