Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Command

Description

loaderRunOneJobAttr(attirbuteDef)

Run an attribute definition loader job

You can run the loader as a linux service so that it auto-starts when the machine boots up

Create a directory for the loader script, pid, and logs (feel free to change dir names etc)

Code Block

 mkdir -p /opt/appserv/grouperLoader

Create the bootstrap script: /opt/appserv/grouperLoader/grouperLoader.sh

Code Block

#!/bin/bash

######################
# customize these vars for your env
pidLocation=/opt/appserv/grouperLoader/grouperLoader.pid
gshBinDirectory=/opt/appserv/tomcat_3b/webapps/grouperWs/WEB-INF/bin
loaderLog=/opt/appserv/grouperLoader/grouperLoader.log
######################

cd $gshBinDirectory
/usr/bin/nohup $gshBinDirectory/gsh -loader > $loaderLog 2>&1 &
echo $! > $pidLocation

Create the service script: /opt/appserv/grouperLoader/grouperLoaderService.sh

Code Block

#!/bin/sh 
#
# Startup script for the Tomcat Server
#
# chkconfig: - 86 14
# description: Grouper loader service
# processname:
# pidfile:
# config:
# Tomcat
# description: Keeps Grouper permissions in sync with file on linux server

#################### CUSTOMIZE THIS FOR YOUR ENV ####################### 
# the user this script should run as

shouldRunAs=appadmin

pidLocation=/opt/appserv/grouperLoader/grouperLoader.pid

#note, this should not contain the gsh command, just the parent directory
gshBinDirectory=/opt/appserv/tomcat_3b/webapps/grouperWs/WEB-INF/bin

#only run on daemon box of cluster.  note, customize this for your env
source /home/appadmin/bin/requireDaemon.sh


grouperLoaderBootstrapScript=/opt/appserv/grouperLoader/grouperLoader.sh
# grouperLoaderBootstrapScript is a way to su as the real user to run the loader
# it has these contents
# #!/bin/bash
#
# pidLocation=/opt/appserv/grouperLoader/grouperLoader.pid
# gshBinDirectory=/opt/appserv/tomcat_3b/webapps/grouperWs/WEB-INF/bin
# loaderLog=/opt/appserv/grouperLoader/grouperLoader.log
#
# cd $gshBinDirectory
# /usr/bin/nohup $gshBinDirectory/gsh -loader > $loaderLog 2>&1 &
# echo $! > $pidLocation



########################################################################

# function to kill a pid, wait for exit...
killPid(){
  pidToKill=$1
  /bin/kill $pidToKill

  #loop until the program is dead
  waitingForExit=true
  iterator=1

  while [ "$waitingForExit" == "true" ]; do

    processIdToKill=`/bin/ps -fp $pidToKill | grep gsh | grep loader | cut -c10-15`
    if [ -n "$processIdToKill" ]; then
      echo Waiting for exit...
    else
      waitingForExit=false
    fi

    if [ "$iterator" -gt "10" ]; then
      waitingForExit=false
    fi

    let "iterator += 1"
    sleep 1
  done

  processIdToKill=`/bin/ps -fp $pidToKill | grep gsh | grep loader | cut -c10-15`
  if [ -n "$processIdToKill" ]; then
    /bin/kill -KILL $pidToKill
    sleep 1

    processIdToKill=`/bin/ps -fp $pidToKill | grep gsh | grep loader | cut -c10-15`
    if [ -n "$processIdToKill" ]; then
      echo "Cannot kill process: $processIdToKill"
      exit 1
    fi  

  fi

}


runningUser=`/usr/bin/whoami`

 
# we only want appadmin or root to be able to do this
if [ "$runningUser" != "$shouldRunAs" ]; then
 
  if [ "$runningUser" != "root"  ]; then
 
    echo "ERROR: only user $shouldRunAs or root can run administer the grouperLoader service: '$runningUser'"
    echo
    exit 1
    
  fi
 
fi
 
case "$1" in
  start)
 
    echo "Starting Grouper loader service..."
 
    #if there is a pid file, and it is running, then exit, else delete
    if [ -f "$pidLocation" ]; then
      pid=`cat $pidLocation`
      processId=`/bin/ps -fp $pid | grep gsh | grep loader | grep "$gshBinDirectory" | cut -c10-15`
      if [ -n "$processId" ]; then
        echo "Grouper loader is already running!"
        exit 1
      else
        echo "PID file exists but loader does not seem to be running"
        rm $pidLocation
      fi
    fi

    # make sure there is not a daemon running which is not in sync with PID file
    processId=`/bin/ps -f | grep gsh | grep loader | grep "$gshBinDirectory" | grep -v /bin/ps | cut -c10-15`
    
    if [ -n "$processId" ]; then
      echo "Alert: Grouper loader is detected to be running, stopping it..."
      processToKill=`/bin/ps -f | grep gsh | grep loader | grep "$gshBinDirectory" | grep -v /bin/ps`
      echo "Killing: $processToKill"
      killPid $processId
    fi

    # make sure there is not a daemon running which is not in sync with PID file
    processId=`/bin/ps -f | grep gsh | grep loader | grep java | grep -v /bin/ps | cut -c10-15`
    
    if [ -n "$processId" ]; then
      echo "Alert: Grouper loader is detected to be running, stopping it..."
      processToKill=`/bin/ps -f | grep gsh | grep loader | grep java | grep -v /bin/ps`
      echo "Killing: $processToKill"
      killPid $processId
    fi

    
    # if not appadmin, then we must be root
    if [ ! "$runningUser" == "$shouldRunAs" ]; then
      su $shouldRunAs -c $grouperLoaderBootstrapScript
    else
      # if not root then we must be appadmin
      $grouperLoaderBootstrapScript
    fi
    echo "Grouper loader is running..."
    ;;
  stop)
      if [ -f "$pidLocation" ]; then 
        pid=`cat "$pidLocation"`
        if [ -n "$pid" ]; then
          echo "Shutting down loader"
          killPid $pid
        else 
          echo "Grouper loader was not running"
        fi
        rm $pidLocation
      else 
        echo "Grouper loader was not running"
      fi

      # make sure there is not a daemon running which is not in sync with PID file
      processId=`/bin/ps -f | grep gsh | grep loader | grep "$gshBinDirectory" | grep -v /bin/ps | cut -c10-15`
    
      if [ -n "$processId" ]; then
        echo "Stopping GSH Grouper load command..."
        processToKill=`/bin/ps -f | grep gsh | grep loader | grep "$gshBinDirectory" | grep -v /bin/ps`
        echo "Killing: $processToKill"
        killPid $processId
      fi
 
      # make sure there is not a daemon running which is not in sync with PID file
      processId=`/bin/ps -f | grep gsh | grep loader | grep java | grep -v /bin/ps | cut -c10-15`
    
      if [ -n "$processId" ]; then
        echo "Stopping GSH Grouper load command..."
        processToKill=`/bin/ps -f | grep gsh | grep loader | grep java | grep -v /bin/ps`
        echo "Killing: $processToKill"
        killPid $processId
      fi
 
    echo
    ;;
  status)
    if [ -f "$pidLocation" ]; then
      pid=`cat "$pidLocation"`
      processId=`/bin/ps -fp $pid | grep gsh | grep loader | grep "$gshBinDirectory" | cut -c10-15`
      if [ -n "$processId" ]; then
        echo "Grouper loader is running under process ID $processId"
      else
        # make sure there is not a daemon running which is not in sync with PID file
        processId=`/bin/ps -f | grep gsh | grep loader | grep java | grep -v /bin/ps | cut -c10-15`
    
        if [ -n "$processId" ]; then
          echo "Grouper loader is running from a PID not in the PID file!"
        else
          echo "Grouper loader is not running"
        fi
      fi
    else
      # make sure there is not a daemon running which is not in sync with PID file
      processId=`/bin/ps -f | grep gsh | grep loader | grep java | grep -v /bin/ps | cut -c10-15`
    
      if [ -n "$processId" ]; then
        echo "Grouper loader is running from a PID not in the PID file!"
      else
        echo "Grouper loader is not running"
      fi

    fi
 
    ;;
  restart)
    echo -n "Restarting Grouper loader: "
    $0 stop
    sleep 5
    $0 start
    echo "done."
    ;;
  *)
    echo "Usage: $0 {start|stop|restart|status}"
    exit 1
esac

Set permissions and register the service:

Code Block

[appadmin@theprince grouperLoader]$ chmod +x /opt/appserv/grouperLoader/grouperLoader.sh
[appadmin@theprince grouperLoader]$ chmod +x /opt/appserv/grouperLoader/grouperLoaderService.sh

[root@theprince init.d]# ln -s /opt/appserv/grouperLoader/grouperLoaderService.sh /etc/init.d/grouperLoader
[root@theprince init.d]# chkconfig --add grouperLoader
[root@theprince init.d]# chkconfig --levels 345 grouperLoader on

You can test this by turning on the service, turning it on again, getting the status, etc

Code Block

sdf

GrouperShell Variables

gsh has several variables that can be set to modify runtime behavior

...