Wednesday, October 08, 2008

Shell Script Consolidation, Part 2

After the success in consolidating the Sun ONE Web Server scripts, I tried to tackle those scripts for the middleware. The middleware includes content management server and application server. To complicate the matter, two instances of the same middleware are running in the same box and listening at different ports.

The logic of the original script is basically to ensure the script has to be executed by a specific user. Also, it will try to find out the status of the process before taking any action (start, stop). Suppose we have:

  1. INSTANCE 1
    Install Directory: /opt/middleware/u01
    User: "user1"
    Executable: /opt/middleware/u01/bin/cms.exe
    Start/Stop script: /opt/scripts/u01/cms.sh
  2. INSTANCE 2
    Install Directory: /opt/middleware/u02
    User: "user2"
    Executable: /opt/middleware/u02/bin/cms.exe
    Start/Stop script: /opt/scripts/u02/cms.sh

The original startup/stop script for the middleware somehow uses an "inverted match" (-v in grep) to check for the existence of process not own by other user. For example in INSTANCE 1, it will try to do this:
RUN=`ps auxwww | grep cms.exe | grep -v grep | grep -v user2 | wc -l`

Although the above command sequence is not foolproof way to locate the correct process, the inverted match managed to work in this case with two instances of the middleware. What will happen if we were to have 3 or more instances running in the same hardware ? I will leave this to my reader to figure that out :-)

In Linux or even in Solaris, you can have a foolproof way to locate the process. The commands that you want to explore are pgrep and pkill
The return code of 0 (zero) from pgrep -u user1 cms.exe > /dev/null 2>&1 will indicate the process "cms.exe" own by "user1" exist.

By right we should only have one set of scripts to handle all the middleware, but "by left" ...

Labels:

0 Comments:

Post a Comment

<< Home