Homepage › Clovertech Forums › Read Only Archives › Cloverleaf › Cloverleaf › HCI command extensions for quick Process/Thread bouncing
- This topic has 12 replies, 4 voices, and was last updated 15 years, 2 months ago by Max Drown (Infor).
-
CreatorTopic
-
July 29, 2009 at 1:53 pm #51087Troy MortonParticipant
Hi everyone, Just curious if anyone out there has TCL or Shell scripts that automate the bouncing of processes and threads within a site.
Thanks!
-
CreatorTopic
-
AuthorReplies
-
-
July 29, 2009 at 8:35 pm #68739Max Drown (Infor)Keymaster
I’m fond of this one. 😛
Code:#!/usr/bin/ksh
# Script: hcibounceprocess
# Author: Troy Morton and Max Drown
# Purpose: Quickly bounce a process and all its threads
# Usage: hcibounceprocess# Check for correct usage
#
if [[ -z “$1” ]]
then
echo “Usage: hcibounceprocess ”
exit 2
fiecho “Preparing to bounce process “$1″ …”
#
# Make sure the process ($1) exists in this site
#
PROCESS=`hciprocstatus | grep “$1 ” | awk ‘{print $1}’`
if [[ “$PROCESS” != “$1” ]]
then
echo “The “$1″ process was not found in $HCISITE.”
echo “Script aborted.”
exit 2
fi#
# If the process was already down, just bring it up
#
STATE=`hciprocstatus | grep “$PROCESS ” | awk ‘{print $2}’`
if [[ “$STATE” = “dead” ]]
then
TRASH=`hcilmclear -p $PROCESS > /dev/null 2>&1`
echo “The “$PROCESS” process is $STATE. Bringing it up…”
TRASH=`hcienginerun -p $PROCESS > /dev/null 2>&1`
STATE=`hciprocstatus | grep “$PROCESS ” | awk ‘{print $2}’`
echo “$PROCESS is: $STATE”
echo “Script done.”
exit 1
fi#
# Get the names of threads in this process that are up
#
THREADSUP=””
THREADS=`hciconnstatus -p $PROCESS | tail –lines=+3 | awk ‘{print $2}’`
for MYTHREAD in $THREADS
do
MYTHREAD_STATUS=`hciconnstatus | grep ” $MYTHREAD ” | awk ‘{print $3}’`
if [[ “$MYTHREAD_STATUS” = “up” ]]
then
THREADSUP=”$THREADSUP $MYTHREAD”
fi
done#
# Stop the process
#
echo “Bringing down the “$PROCESS” process…”
TRASH=`hcienginestop -p $PROCESS > /dev/null 2>&1`
sleep 5
TRASH=`hcilmclear -p $PROCESS > /dev/null 2>&1`#
# Restart the process and all the threads that were up when it was stopped
#
echo “Starting the “$PROCESS” process and the following threads :”
if [[ -z “$THREADSUP” ]]
then
echo “NONE”
TRASH=`hcienginerun -p $PROCESS > /dev/null 2>&1`
else
echo “$THREADSUP”
TRASH=`hcienginerun -p $PROCESS -s “$THREADSUP” > /dev/null 2>&1`
fisleep 5
STATE=`hciprocstatus | grep “$PROCESS ” | awk ‘{print $2}’`
echo “$PROCESS is: $STATE”
echo “Script done.”# End of Script
-- Max Drown (Infor)
-
July 29, 2009 at 8:40 pm #68740Troy MortonParticipant
I figured you might still have that one. Would it be much trouble for you to send me copies of all those handy scripts we created?
-
July 29, 2009 at 8:43 pm #68741Max Drown (Infor)Keymaster
Absolutely.
-- Max Drown (Infor)
-
July 31, 2009 at 6:09 pm #68742Bob RichardsonParticipant
Folks,
We have defined some functions in our Cloverleaf user account “hci” and “hcitest” to perform some of these tasks more easily with less typing.
We use the .profile.local.end file to store these functions. You then invoke them at the shell command line.
Here are some samples to cycle a process; stop/start a thread; and do a purge cache of a process. Hopefully they will prove useful.
function cycle {
if -z $1 ; then
echo “Syntax: cycle “;return
fi
if grep $1) ; then
echo “$1 process not found”;return
fi
hcienginestop -p $1
sleep 1
hcienginerun -p $1
echo “cycle $1 complete”
}
function purge {
if -z $1 ; then
echo “Syntax: purge “;return
fi
if grep $1) ; then
echo “Process ($1) not found”;return
fi
hcicmd -p $1 -c ‘ . purgex’
echo “purge $1 complete”
}
function bounce {
if -z $1 ; then
echo “Syntax: bounce “;return
fi
PROCESS=$(hciconnstatus|awk ‘$2 == Thread {print $1}’ Thread=$1)
if -z $PROCESS ; then
echo “Thread ($1) not found”;return
fi
hcicmd -p $PROCESS -c “$1 pstop”
sleep 1
hcicmd -p $PROCESS -c “$1 pstart”
echo “bounce $1 complete”
}
-
August 13, 2009 at 5:29 pm #68743Michael HertelParticipant
Hi Bob,
We use tcsh here so we have .cshrc.local.end
Is there a way to use your functions with tcsh?
-
August 13, 2009 at 5:53 pm #68744Bob RichardsonParticipant
Greetings Michael,
I take it that you are running on Linux? We run on AIX5.3 and use ksh shell. In poking around the web, it appears that the C shell (csh) emulates the C programming language. You would think that something like a function (or subroutine) could be invoked from a C shell?
Alas, I did not find any useful web links out there but then my search lasted only a half hour.
Does anyone on this Forum work with the C shell who could help out Michael?
May the silicon gods be merciful in your quest…
-
August 13, 2009 at 5:56 pm #68745Troy MortonParticipant
I would suggest getting the O’Reilly book UNIX in a Nutshell. This book describes some of the differences between the different shells.
If nothing else, you can copy the code and place it in a commonly acessible place like /usr/local/bin so that it could be executed from any location on the server.
Cheers,
Troy
-
August 13, 2009 at 6:01 pm #68746Michael HertelParticipant
Thanks Bob.
I am on AIX.
Back in 1996 when I witnessed my first Cloverleaf install by Greg Wood,
I saw that he used tcsh. I think the hcispt1 account still uses it.
So I’ve used it ever since.
I love it because of the completion and /
features.
Anyhow, maybe I can get my Unix Admins to convert the scripts. Unfortunately it’s gonna cost me.
-
August 13, 2009 at 6:08 pm #68747Max Drown (Infor)Keymaster
You should be able to run any script from any shell by adding the appropriate header. In this case, the header might be “#!/bin/csh”? Do a which “csh” from your command line.
-- Max Drown (Infor)
-
August 13, 2009 at 7:14 pm #68748Michael HertelParticipant
Right, I could put those commands into a ksh script and exec it that way.
I liked the idea that I could do that as part of .cshrc.local.end
-
August 13, 2009 at 7:25 pm #68749Max Drown (Infor)KeymasterMichael Hertel wrote:
Right, I could put those commands into a ksh script and exec it that way.
I liked the idea that I could do that as part of .cshrc.local.end
You can write your own versions of the functions for tcsh and then put them into .tcshrc.local.end (or whatever file you want). This file is sourced (. .profile.local.end) by .profile when the hci user logs in.
I use the bash shell. Here are some example bash functions that I have in .profile.local.end:
Code:function cdr () { cd $HCIROOT/$1; }
function cds () { cd $HCISITEDIR/$1; }It’s just a matter of looking up the function syntax for .tcsh.
-- Max Drown (Infor)
-
August 13, 2009 at 7:52 pm #68750Max Drown (Infor)Keymaster
here’s a nice shell script I got from Jerry. I modified it a bit.
Code:#!/usr/bin/ksh
export CL_INSTALL_DIR=/hci/quovadx/qdx5.6
eval `${CL_INSTALL_DIR}/integrator/sbin/hcisetenv -root ksh ${CL_INSTALL_DIR}/integrator $1`if [ $4 = “stop” ]
then
echo `hcicmd -p $2 -c “$3 pstop”`
sleep 1
elif [ $4 = “start” ]
then
echo `hcicmd -p $2 -c “$3 pstart”`
sleep 1
elif [ $4 = “hold” ]
then
echo `hcicmd -p $2 -c “$3 phold_obd”`
sleep 1
elif [ $4 = “release” ]
then
echo `hcicmd -p $2 -c “$3 prls_obd”`
sleep 1
else
echo “Usage: threadctl.tcl ”
fi-- Max Drown (Infor)
-
-
AuthorReplies
- The forum ‘Cloverleaf’ is closed to new topics and replies.