HCI command extensions for quick Process/Thread bouncing

Homepage Clovertech Forums Read Only Archives Cloverleaf Cloverleaf HCI command extensions for quick Process/Thread bouncing

  • Creator
    Topic
  • #51087
    Troy Morton
    Participant

    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!

Viewing 11 reply threads
  • Author
    Replies
    • #68739

      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
      fi

      echo “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`
      fi

      sleep 5
      STATE=`hciprocstatus | grep “$PROCESS ” | awk ‘{print $2}’`
      echo “$PROCESS is: $STATE”
      echo “Script done.”

      # End of Script

      -- Max Drown (Infor)

    • #68740
      Troy Morton
      Participant

      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?

    • #68741

      Absolutely.

      -- Max Drown (Infor)

    • #68742
      Bob Richardson
      Participant

      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”

      }

    • #68743
      Michael Hertel
      Participant

      Hi Bob,

      We use tcsh here so we have .cshrc.local.end

      Is there a way to use your functions with tcsh?

    • #68744
      Bob Richardson
      Participant

      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…

    • #68745
      Troy Morton
      Participant

      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

    • #68746
      Michael Hertel
      Participant

      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.

    • #68747

      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)

    • #68748
      Michael Hertel
      Participant

      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

    • #68749

      Michael 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)

    • #68750

      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)

Viewing 11 reply threads
  • The forum ‘Cloverleaf’ is closed to new topics and replies.

Forum Statistics

Registered Users
5,042
Forums
28
Topics
9,200
Replies
34,023
Topic Tags
267