Versions Compared

Key

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

...

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

...

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

Code Block

[appadmin@mamapalma ~]$ ps -ef | grep gsh
appadmin   856   518  0 17:01 pts/0    00:00:00 grep gsh
[appadmin@mamapalma ~]$ /sbin/service grouperLoader stop
Grouper loader was not running




[appadmin@mamapalma ~]$ /sbin/service grouperLoader status
Grouper loader is not running
[appadmin@mamapalma ~]$ /sbin/service grouperLoader start
Starting Grouper loader service...
Grouper loader is running...
[appadmin@mamapalma ~]$ ps -ef | grep gsh
appadmin   927     1  0 17:01 pts/0    00:00:00 /bin/sh /opt/appserv/tomcat_3b/webapps/grouperWs/WEB-INF/bin/gsh -loader
appadmin   928   927 99 17:01 pts/0    00:00:09 java -Xms64m -Xmx750m -Dgrouper.home=/opt/appserv/tomcat_3b/webapps/grouperWs/WEB-INF/bin/../ -classpath /opt/appserv/tomcat_3b/webapps/grouperWs/WEB-INF/bin/../classes:/opt/appserv/tomcat_3b/webapps/grouperWs/WEB-INF/bin/../lib/*: edu.internet2.middleware.grouper.app.gsh.GrouperShellWrapper -loader
appadmin   957   518  0 17:01 pts/0    00:00:00 grep gsh
[appadmin@mamapalma ~]$ more /opt/appserv/grouperLoader/grouperLoader.pid 
927
[appadmin@mamapalma ~]$ /sbin/service grouperLoader status
Grouper loader is running under process ID   927 
  928 
[appadmin@mamapalma ~]$ /sbin/service grouperLoader start
Starting Grouper loader service...
Grouper loader is already running!
[appadmin@mamapalma ~]$ cat 123 > /opt/appserv/grouperLoader/grouperLoader.pid 
cat: 123: No such file or directory
[appadmin@mamapalma ~]$ echo "123" > /opt/appserv/grouperLoader/grouperLoader.pid 
[appadmin@mamapalma ~]$ /sbin/service grouperLoader status
Grouper loader is running from a PID not in the PID file!
[appadmin@mamapalma ~]$ /sbin/service grouperLoader start
Starting Grouper loader service...
PID file exists but loader does not seem to be running
Alert: Grouper loader is detected to be running, stopping it...
Killing: appadmin   927     1  0 17:01 pts/0    00:00:00 /bin/sh /opt/appserv/tomcat_3b/webapps/grouperWs/WEB-INF/bin/gsh -loader
appadmin   928   927 10 17:01 pts/0    00:00:10 java -Xms64m -Xmx750m -Dgrouper.home=/opt/appserv/tomcat_3b/webapps/grouperWs/WEB-INF/bin/../ -classpath /opt/appserv/tomcat_3b/webapps/grouperWs/WEB-INF/bin/../classes:/opt/appserv/tomcat_3b/webapps/grouperWs/WEB-INF/bin/../lib/*: edu.internet2.middleware.grouper.app.gsh.GrouperShellWrapper -loader
Alert: Grouper loader is detected to be running, stopping it...
Killing: appadmin   928     1 10 17:01 pts/0    00:00:10 java -Xms64m -Xmx750m -Dgrouper.home=/opt/appserv/tomcat_3b/webapps/grouperWs/WEB-INF/bin/../ -classpath /opt/appserv/tomcat_3b/webapps/grouperWs/WEB-INF/bin/../classes:/opt/appserv/tomcat_3b/webapps/grouperWs/WEB-INF/bin/../lib/*: edu.internet2.middleware.grouper.app.gsh.GrouperShellWrapper -loader
Waiting for exit...
Grouper loader is running...
[appadmin@mamapalma ~]$ ps -ef | grep gsh
appadmin  1133     1  0 17:03 pts/0    00:00:00 /bin/sh /opt/appserv/tomcat_3b/webapps/grouperWs/WEB-INF/bin/gsh -loader
appadmin  1134  1133 99 17:03 pts/0    00:00:08 java -Xms64m -Xmx750m -Dgrouper.home=/opt/appserv/tomcat_3b/webapps/grouperWs/WEB-INF/bin/../ -classpath /opt/appserv/tomcat_3b/webapps/grouperWs/WEB-INF/bin/../classes:/opt/appserv/tomcat_3b/webapps/grouperWs/WEB-INF/bin/../lib/*: edu.internet2.middleware.grouper.app.gsh.GrouperShellWrapper -loader
appadmin  1164   518  0 17:03 pts/0    00:00:00 grep gsh
[appadmin@mamapalma ~]$ /sbin/service grouperLoader stop
Shutting down loader
Stopping GSH Grouper load command...
Killing: appadmin  1134     1 67 17:03 pts/0    00:00:10 java -Xms64m -Xmx750m -Dgrouper.home=/opt/appserv/tomcat_3b/webapps/grouperWs/WEB-INF/bin/../ -classpath /opt/appserv/tomcat_3b/webapps/grouperWs/WEB-INF/bin/../classes:/opt/appserv/tomcat_3b/webapps/grouperWs/WEB-INF/bin/../lib/*: edu.internet2.middleware.grouper.app.gsh.GrouperShellWrapper -loader
Waiting for exit...




[appadmin@mamapalma ~]$ ps -ef | grep gsh
appadmin  1248   518  0 17:03 pts/0    00:00:00 grep gsh
[appadmin@mamapalma ~]$ /sbin/service grouperLoader start
Starting Grouper loader service...
Grouper loader is running...
[appadmin@mamapalma ~]$ /sbin/service grouperLoader status
Grouper loader is running under process ID  1279 
[appadmin@mamapalma ~]$ /sbin/service grouperLoader status
Grouper loader is running under process ID  1279 
[appadmin@mamapalma ~]$ /sbin/service grouperLoader status
Grouper loader is running under process ID  1280 

sdf

GrouperShell Variables

...