Date: Sat, 5 Mar 2016 13:21:33 +0200 From: Esa Karkkainen <ejk@iki.fi> To: freebsd-questions@freebsd.org Subject: Re: Check which services/processes need restart after update Message-ID: <20160305112133.GB4778@pp.htv.fi> In-Reply-To: <BF442EB7-5F98-4ABC-A000-A6C037BE8C9A@wellmann-engineering.eu> References: <BF442EB7-5F98-4ABC-A000-A6C037BE8C9A@wellmann-engineering.eu>
index | next in thread | previous in thread | raw e-mail
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
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20160305112133.GB4778>
