Comment 3 for bug 103436

Revision history for this message
Perry E. Metzger (perry-piermont) wrote : Re: [Bug 103436] Re: sshd not reconfigured by /etc/network

Colin Watson <email address hidden> writes:
> Well, I can tell for a start that the above isn't right because what if
> sshd isn't running?

Then no real harm is caused -- but several of the other scripts in
network happily test for this sort of thing already.

Here is how to do it. The test you are looking for is to check if
/var/run/sshd.pid is there, and if so, if the running process is in
fact sshd, which is done by checking /proc/pid/exe.

if [ -f /var/run/sshd.pid ]
then
    if [ -h /proc/$(cat /var/run/sshd.pid)/exe ]
    then
        NAME=$(ls -l /proc/$(cat /var/run/sshd.pid)/exe | sed 's/^.*\///' )
        if [ $NAME = "sshd" ]
        then
            /etc/init.d/sshd restart
        fi
    fi
fi

This is straightforward. (You should of course test the code.)

> That's why I didn't just fix it on the spot, because it isn't
> entirely trivial and I wanted to think about it a bit.

Well, the code to do what you want is above.

See also bug #120199 if you fix the above one.

Feel free to bother me if you need any more shell magic like the stuff
above written.

Perry