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
Tags: rpm
If you are on a Debian box, just install debian-goodies and run the checkrestart program.
Hi,
have a look at yum-plugin-ps in RHEL6 and Fedora. This should do the same thing.
CU
Jens
The yum-utils package contains a python script called “needs-restarting”.
Jens, yum ps won’t work on rhel5, though, as it needs newer versions of yum.
On the other hand, Samuel, needs-restarting works on rhel5, so it’s a pity it isn’t included. And it even has lower runtime, as it uses yum infrastructure instead of forking off rpm, than my script. (Though in my oppinion, it has uglier output).
Thank you both.
Ingvar
There’s no yum-utils package in rhel5 or the needs-restarting script isn’t in that package?
Samuel,
yum-utils exists in RHEL5, but needs-restarting is missing. Which is a shame, since the script seems to work well. Feature request, I guess. Perhaps worth a BZ ticket, so I added one:
https://bugzilla.redhat.com/show_bug.cgi?id=784895