Scripting the stop and restart of SRC controlled processes on AIX

I wanted to make sure this information did not get lost. IBM decided to close the developerworks forums. Credit goes to Brian Smith. Not sure how much longer this link will be valid.

https://webcache.googleusercontent.com/search?q=cache:TNuA5Fhme-MJ:https://www.ibm.com/developerworks/community/blogs/brian/date/201303+&cd=2&hl=en&ct=clnk&gl=us&client=firefox-b-1-d

Scripting the stop and restart of SRC controlled processes on AIX

brian_s | | Tags: aix script ‎ | 1 Comment ‎ | 40,129 Views

Most SRC controlled processes support the "refresh -s" command to have them re-read their configuration files after a change. For example, if you edit the inetd.conf configuration file you just do a "refresh -s inetd" and inetd will re-read the configuration file and you are good to go.

However, some SRC controlled processes, such as SSHD, do not support this:

# refresh -s sshd0513-005 The Subsystem, sshd, only supports signal communication.

In order to have a process such as SSHD re-read its configuration file (/etc/ssh/sshd_config), you must do a "stopsrc -s sshd" followed by a "startsrc -s sshd":

# stopsrc -s sshd0513-044 The sshd Subsystem was requested to stop.# startsrc -s sshd0513-059 The sshd Subsystem has been started. Subsystem PID is 3670044.

As you can see when you do the "stopsrc" it just says the process was requested to stop; not that it was stopped. This implies that there might be a delay before the process actually stops.

So what a lot of people do in scripts where they need to restart processes like this is something like this:

stopsrc -s sshd

sleep 10startsrc -s sshd

However; there are some problems with this methodology. First, if the process takes longer than 10 seconds to stop for some reason, then your startsrc command would fail, and then when the process finally did stop, you would be left with a system without SSHD running. Second, during this 10 second sleep SSHD isn't running and new connections won't be able to be established which might impact thesystem.

Here is a one liner to request a stop to a SRC process like SSHD, verify it is stopped, and then restart it:

stopsrc -s sshd && until lssrc -s sshd | grep -q inoperative; do echo "Waiting for sshd to stop"; perl -e 'select(undef,undef,undef,.25)'; done && startsrc -s sshd

Basically, what it will do is request the SSHD process be stopped, then use an "until" loop to wait until lssrc -s sshd reports it is inoperative. While it is waiting, it will sleep for 0.25 seconds before checking again. The perl -e 'select(undef, undef, undef, .25)' is a easy way to sleep for less than 1 second. After the process is verified to have stopped, it is started again.

3 Likes

I wonder how it can take >10 seconds to take down the sshd.?

Reminds me of the sshd in Solaris 10 and 11; it must be compiled with a special adaption: for each forked sshd child it needs to switch the ctid (contract ID).
In case you use a sshd from openssh in favor of the (older) stock sshd, be careful it is compiled with such an OS-specific adaption!

To reread its configuartion the sshd usually takes a kill -HUP on its master pid.
In Solaris and Linux and HP-UX you can do

pkill -HUP -xou 0 sshd

Or you can use the sshd pidfile:


kill -HUP `cat /path/to/sshd.pid`

1 Like

Well it did not take long for the link to be dropped...
404. That’s an error.

The requested URL /search?q=cache:TNuA5Fhme-MJ:https://www.ibm.com/developerworks/community/blogs/brian/date/201303+&cd=2&hl=en&ct=clnk&gl=us&client=firefox-b-1-d was not found on this server. That’s all we know.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.