Posts Tagged ‘rpm’

Today’s sysadmin tip: Finding what binaries to restart

Thursday, January 19th, 2012

When I started working with Linux system administration a few years ago, restarting services after a package upgrade was fairly easy. If the package didn’t restart itself, one could always ask lsof for help:

lsof +L1 | egrep 'bin/|lib/'

Now, on later Linux distributions, the usage of prelink has changed this, so one usually gets a lot of false positives, and could never trust the result of that good old lsof output.

Finding running executables is possible using some perl magic (Yes, I’m pretty sure you perl guys can write this more compressed) along the lines of this, at least on RHEL5:

perl -e ' for $i (glob "/proc/[1-9]*/exe") { $f=readlink $i; if ( $f=~ /([^\0]+)\0.*deleted/ ) { print "$1\n" }} ' | sort | uniq

But this won’t help us finding what service to restart after a dependency library was updated. So I finally wrote this script to help me. My boxes are mostly Fedora and RHEL, so it uses the fact that installed binaries on Red Hat based systems have installation time stored in the rpm database (rpm tag %{INSTALLTIME} ). This script abuses rpm heavily, and may use some time to finish on a busy system.

http://users.linpro.no/ingvar/check_newlibs

Test run:

[root]# /home/ingvar/check_newlibs 
Warning: Needs restart: /sbin/agetty, pids 6067
Warning: Needs restart: /usr/bin/tail, pids 7315
Warning: Needs restart: /usr/bin/vim, pids 19759
Warning: Needs restart: /usr/sbin/sendmail.sendmail, pids 10645 10637
Warning: Needs restart: /usr/sbin/acpid, pids 5259
Warning: Needs restart: /usr/sbin/crond, pids 5567
Warning: Needs restart: /bin/bash, pids 26074 17731 16848 15718 30753 6120 32704
Warning: Needs restart: /sbin/mingetty, pids 6071 6069 6076 6068 6072 6070
Warning: Needs restart: /sbin/portmap, pids 5082
Warning: Needs restart: /usr/sbin/smartd, pids 20948
Warning: Needs restart: /sbin/multipathd, pids 20170
Warning: Needs restart: /usr/sbin/atd, pids 5969
Warning: Needs restart: /usr/sbin/sshd, pids 19863
Warning: Needs restart: /usr/libexec/mysqld, pids 17775