Check which services/processes need restart after update

Esa Karkkainen ejk at
Sat Mar 5 11:29:10 UTC 2016

On Thu, Mar 03, 2016 at 10:07:21PM +0100, Walkenhorst, Benjamin wrote:
> 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

# cat /root/bin/check_services
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
if [ -e /var/run/ ] ; then
        cp /dev/null /var/run/ || exit 1
        touch /var/run/ || exit 1
        chown root:wheel /var/run/ || exit 1
        chmod 0640 /var/run/ || exit 1
for i in list of services to be monitored
        service $i status >> /var/run/ 2>&1
        pid="$(tail -1 /var/run/|tr -d '.'|awk '{print
        if [ -z "${pid}" ] ; then
                service "${i}" start
unset i
diff -u /var/run/check_services.prev /var/run/ 2>&1
if cmp -s /var/run/check_services.prev /var/run/ ;
        mv /var/run/ /var/run/check_services.prev ||
exit 1
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