1834827 Members
1871 Online
110070 Solutions
New Discussion

package controll scripts

 
SOLVED
Go to solution
Ralph Grothe
Honored Contributor

package controll scripts

While doing script adjustments of SG's package control script I had a look at the therein defined test_return() function.
Basically it only checks if the previous command's/processe's exit code is ne 0, and if so falls into a case construct to match against certain codes.
It looks as if for the customer_defined* funcs the codes 51, 52 are reserved.
I would like to further fine grade this (viz. inventing some new rc value, which only throws a warning, but doesn't do an application kill, and unmount and unactivation of the packages VG.

So what codes can I use (in order to cling to some SG standard)?
Would any value (in the range of shell arithmetic) above 52 be ok?
Madness, thy name is system administration
4 REPLIES 4
Jim Carter_1
Advisor

Re: package controll scripts

Your best solution is probably to leave the control script as delivered, but make your change in the "user defined [start|halt] function" area. You realize the test_return 51|52 only catch the immediatly preceeding return code, so if you want to deal with interim codes (several steps in your start or halt processes) you should either code them in at that location, or call external code to treat them as you wish.

I do this a lot to modify the "/etc/issue" file. I chrc a value into the file that shows which package is running on which node and at what time it started. (Isn't scripting wonderful?)
Just because I'm paranoid doesn't mean they're not out to get me
Rich Wright
Trusted Contributor
Solution

Re: package controll scripts

Yes, here is an example.
We have a Data Base package that must be running before this Application can be started.
We have a customer defined function that checks the Data Base status. If it fails, then test_return will take the appropriate action. Here is the code from the .cntl file. 1st the function. 2nd the call to the function then call to test_return. 3rd the test_return case code


Hope this helps.
----1st------
# START OF CUSTOMER DEFINED FUNCTIONS

# This function is a place holder for customer defined functions.
# You should define all actions you want to happen here, before the service is
# started. You can create as many functions as you need.

function Check_DB_package
{
# This function checks to see if the DB package is running
# If it is not it will sleep and try again. This is repeated 'DB_RETRY'
# times.

DATE=`date '+%b %d %X'`
print "${DATE} - Waiting for DB package $DB_PKG to come up!"

while [ $DB_RETRY -ge 0 ];do
CHK_DB=`cmviewcl -p $DB_PKG | tail -1 | awk '{print $2}'`
if [[ "$CHK_DB" = "up" || "$CHK_DB" = "starting" ]];then
DATE=`date '+%b %d %X'`
print "${DATE} - Database is up. Starting application"
return 0
else
DATE=`date '+%b %d %X'`
print "${DATE} - Waiting for DB Package to come up ($DB_RETRY)"
sleep 10
((DB_RETRY=DB_RETRY - 1))
fi
done

# If we get this far then we know that the retry loop expired before the
# database came up. Therefore we will return a failure.

return 1
}

-----2nd--------
Check_DB_package
test_return 51
-----3rd--------
# Test return value of functions and exit with NO RESTART if bad.
# Return values of 0 - 50 are reserved for use by Hewlett-Packard.
# System administrators can use numbers above 50 for return values.
function test_return
{
if (( $? != 0 ))
then
case $1 in
... std stuf ...

51)
print "\tERROR: Function customer_defined_run_cmds"
print "\tERROR: Failed waiting for DB Package to come up"
remove_ip_address
un_export_fs
halt_nfs_services
nfs_defined_halt_cmds
umount_fs
deactivate_volume_group
QUIT 1
;;

-------end---------
Ralph Grothe
Honored Contributor

Re: package controll scripts

Ouch, I once again made a complete idiot of myself with this thread.
How on earth could I overlook the comment lines *right at the start* of the function definition of test_return? %-{

# Test return value of functions and exit with NO RESTART if bad.
# Return value of 0 - 50 are reserved for use by Hewlett-Packard.
# System administrators can use numbers above 50 for return values.
function test_return

That was all the info I needed.

Now I will insert my own custom 'case' matches with codes above 52 to handle my own exceptions.

I award you the 10 pts. not so much for supplying me with your sample script but for including this vital comment line in your sample that I had overlooked ;-)

Madness, thy name is system administration
Jim Carter_1
Advisor

Re: package controll scripts

Ralph,
I didn't make my point about modifying the "case" statement properly. If you modify the statement, which was generated by the cmmakepkg -s command, you risk someone coming behind you and overlaying your modifications by running the command again. If the only thing you have to put back into place is a call to your external code, it's much easier to maintain / fix.
I realize this may seem trivial, but I believe in Defensive Programming. You can solve your issue either way....
Just because I'm paranoid doesn't mean they're not out to get me