Scripting the stop and restart of SRC controlled processes on AIX
brian_s 270002K5X3 Comment (1) Visits (25874)
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:
In order to have a process such as SSHD re-read its configuration file (/et
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:
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:
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.