April 9, 2012
What to restart after a system upgrade ?

If you’re familiar with Windows, you know rebooting is something pretty common. You’re usually asked to reboot after a system upgrade, after (or in order to) installing a new application, after removing one…

And one of the thing you hear about Linux, is that you almost never need to reboot. Unless you install a new kernel, rebooting is not necessary, but that doesn’t mean you don’t have to restart a few things.

It was actually one question I had early on after moving to Linux : how to know what to restart after a system upgrade ?

Some things are pretty obvious: if you upgraded Firefox to a new version, you’ll have to restart it.

Similarly, having upgraded the X server, it needs to be restarted. I’m not exactly sure how that works when one uses a Display Manager, but as it turns out I don’t (I use the great xlsh to log in, and auto-start my X session through .bash_profile), so when I need to restart X, I just log out and back in.

But things gets a bit more complicated when it comes to libraries. Because it’s not always obvious which application uses a given library, even when you know what said library does.

A little trick I found recently that can help with that, is using lsof. It’s a great tool that can list all opened files, and of course that also includes deleted files.

So, one can easily use it and grep the list of all opened files whose name contains “lib” - as is often if not always the case for libraries - and then we get the list of applications that are still using old/deleted versions of one or more libraries. Or, of applications that should be restarted.

Now because I’m curious I guess, I like to know why a given app needs to be restarted, so I tweaked it a bit, so that it not only gives the application to restart; but also the name of the deleted library it uses :

lsof +c 0 | grep 'DEL.*lib' | awk '1 { print $1 ": " $NF }' | sort -u

Automaticly check for deleted libraries in use after a sysupgrade

As you might know, I do my system upgrades through kalu & its system updater. And one thing it allows you to do, is define some process to be ran after each sysupgrade.

Now because this is all done from a GUI, I wanted this to also be done through a GUI and not by opening a terminal. So here’s the little script I made :

#!/bin/bash
ret=2
while [ $ret -eq 2 ]; do
    LIST=$(lsof +c 0 | grep 'DEL.*lib' | awk '1 { print $1 ": " $NF }' | sort -u)
    if [[ $LIST = "" ]]; then
        ic-info 'No deleted libraries in use found'
        exit 0
    fi
    echo "$LIST" | ic-text -e Refresh -E gtk-refresh -T 'Deleted Libraries In Use'
    ret=$?
done

This makes use of intercourse to provide GUI elements, but of course you could use anything else, e.g. zenity.

Restarting XFCE panel ?

As I mentionned earlier, I don’t use a Display Manager, and upon login a new X session is automatically started via my .bash_profile

One more thing I don’t use, is a session manager, not XFCE’s own or any other. As far as I can tell, what this would do besides eat ressources is make note of running applications when I log out, to start them back when I log in. Definately not something I have any interest in.

Something else it would do, is get me buttons to restart or shutdown the computer. But I don’t care for that, since I can do it from my xlsh shell.

But as a result, when I want to close th XFCE panel, I get a little warning : You have started X without session manager. Clicking Quit will close the X server.

This is a bit unfortunate, because it means that I can’t restart the panel without closing X, any running X apps while at it, and logging me out. Of course, there’s a way around this.

xfce-utils comes with a xinitrc that already takes care of panel crash. In such an event, you get a little message (using xmessage) about it, and the panel is restarted. So I just edited my ~/.config/xfce4/xinitrc to have the ability to either log out, or simply restart the panel, e.g. so it can use a newly-upgraded library.

while true; do
        if test $ret -ne 0; then
                ic-error -T Error 'A crash occured in the panel' -D <<EOF
Please report this to the xfce4-dev@xfce.org list
or on http://bugs.xfce.org
Meanwhile the panel will be restarted
EOF
                cat >&2 <<EOF
A crash occured in the panel
Please report this to the xfce4-dev@xfce.org list
or on http://bugs.xfce.org
Meanwhile the panel will be restarted
EOF
        else
                # 3 = closed w/out button; 1 = Restart; 0 = Close & log out
                ic-question -T 'Logging out?' \
                -b 'Close X and log out' -i gtk-quit \
                -B 'Restart panel' -I gtk-refresh \
                'Do you want to close X & log out ?' \
                -d 'Closing X will terminate all running programs. Better to close them properly first.'
                if test $? -eq 0; then
                        break
                fi
        fi
        $panel
        ret=$?
done

  1. mywaytoarch posted this
Blog comments powered by Disqus