Date: Thu, 28 Mar 2024 20:41:59 +0000 (UTC) Message-ID: <2090022057.6969.1711658519468@ip-10-10-7-29.ec2.internal> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_6968_860109342.1711658519466" ------=_Part_6968_860109342.1711658519466 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
You can run the loader as a linux service so that it auto-starts when th= e machine boots up. This is outdated, the loader (daemon) runs in the= container
Note, here are systemd scripts
Create a directory for the loader script, pid, and logs (feel free to ch= ange dir names etc). Note, in our case, the appserv dir is sync'ed ac= ross the cluster, the /opt/grouperLoader dir is not, so that is used for th= e pid and logs
mkdir -= p /opt/appserv/grouperLoader mkdir -p /opt/grouperLoader chown appadmin.users /opt/grouperLoader
Create the bootstrap script: /opt/appserv/grouperLoader/grouperLoader.sh=
Note, test the script as below, and make sure all the commands are in th= e right place, e.g. /bin/kill, /bin/ps, etc
#!/bin/= bash export JAVA_HOME=3D/opt/appserv/java6 export PATH=3D$JAVA_HOME/bin:$PATH pidLocation=3D/opt/grouperLoader/grouperLoader.pid gshBinDirectory=3D/opt/appserv/tomcat_3b/webapps/grouperWs/WEB-INF/bin loaderLog=3D/opt/grouperLoader/grouperLoader.log cd $gshBinDirectory theDate=3D`date` /usr/bin/nohup $gshBinDirectory/gsh -loader >> $loaderLog 2>&1= & pid=3D$! echo $pid > $pidLocation echo >> $loaderLog echo "##############################" >> $loaderLog echo "## $theDate: started Grouper loader... ($pid)" >> $loaderLog echo "##############################" >> $loaderLog echo >> $loaderLog
Create the service script: /opt/appserv/grouperLoader/grouperLoaderServi= ce.sh
#!/bin/= bash # # Startup script for the Tomcat Server # # chkconfig: - 86 14 # description: Grouper loader service # processname: # pidfile: # config: # Tomcat # description: Starts the grouper loader #################### CUSTOMIZE THIS FOR YOUR ENV #######################=20 # the user this script should run as shouldRunAs=3Dappadmin pidLocation=3D/opt/appserv/local/grouperLoader/grouperLoader.pid #note, this should not contain the gsh command, just the parent directory gshBinDirectory=3D/opt/appserv/tomcat/apps/grouperWs/loader/bin #only run on daemon box of cluster. note, customize this for your env # source /home/appadmin/bin/requireDaemon.sh loaderLog=3D/opt/appserv/local/grouperLoader/grouperLoader.log grouperLoaderBootstrapScript=3D/opt/appserv/common/grouperLoader/grouperLoa= der.sh # grouperLoaderBootstrapScript is a way to su as the real user to run the l= oader # it has these contents # # #!/bin/bash # # export JAVA_HOME=3D/opt/appserv/java6 # export PATH=3D$JAVA_HOME/bin:$PATH # # pidLocation=3D/opt/grouperLoader/grouperLoader.pid # gshBinDirectory=3D/opt/appserv/tomcat_3b/webapps/grouperWs/WEB-INF/bin # loaderLog=3D/opt/grouperLoader/grouperLoader.log # # cd $gshBinDirectory # theDate=3D`date` # /usr/bin/nohup $gshBinDirectory/gsh -loader >> $loaderLog 2>&= ;1 & # pid=3D$! # echo $pid > $pidLocation # echo >> $loaderLog # echo "##############################" >> $loaderLog # echo "## $theDate: started Grouper loader... ($pid)" >> $loaderLog # echo "##############################" >> $loaderLog # echo >> $loaderLog ######################################################################## # function to kill a pid, wait for exit... killPid(){ pidToKill=3D$1 /bin/kill $pidToKill #loop until the program is dead waitingForExit=3Dtrue iterator=3D1 while [ "$waitingForExit" =3D=3D "true" ]; do # xargs will trim the string processIdToKill=3D`/bin/ps -fp $pidToKill | grep gsh | grep loader | gr= ep -v /bin/ps | cut -c10-15 | xargs` if [ -n "$processIdToKill" ]; then echo Waiting for exit... else # lets just make sure: (sometimes process isnt found with -fp...) /bin/kill -KILL $pidToKill > /dev/null 2>&1 waitingForExit=3Dfalse fi if [ "$iterator" -gt "10" ]; then waitingForExit=3Dfalse fi let "iterator +=3D 1" if [ "$waitingForExit" =3D=3D "true" ]; then sleep 1 fi done processIdToKill=3D`/bin/ps -fp $pidToKill | grep gsh | grep loader | grep= -v /bin/ps | cut -c10-15 | xargs` if [ -n "$processIdToKill" ]; then /bin/kill -KILL $pidToKill sleep 1 processIdToKill=3D`/bin/ps -fp $pidToKill | grep gsh | grep loader | gr= ep -v /bin/ps | cut -c10-15 | xargs` if [ -n "$processIdToKill" ]; then echo "Cannot kill process: $processIdToKill" exit 1 fi =20 fi } # get the process id of the gsh process, put into the variable theGshProces= sId # if pass "true" as arg, then exit if there are multiple running gshProcessId(){ if [ "$1" =3D=3D "true" ]; then numberOfProcesses=3D`/bin/ps -ef | grep $gshBinDirectory | grep gsh | g= rep loader | grep -v /bin/ps | grep edu.internet2.middleware.grouper.app.gs= h.GrouperShellWrapper | wc -l`=20 if [ "$numberOfProcesses" -gt "1" ]; then echo "Grouper loader is running multiple times!!!" exit 1 fi fi theGshProcessId=3D`/bin/ps -ef | grep $gshBinDirectory | grep gsh | grep = loader | grep -v /bin/ps | grep edu.internet2.middleware.grouper.app.gsh.Gr= ouperShellWrapper | head -1 | cut -c10-15 | xargs` } # get the parent process id of the gsh process, put into the variable theGs= hParentProcessId gshParentProcessId(){ theGshParentProcessId=3D`/bin/ps -ef | grep /bin/sh | grep $gshBinDirecto= ry | grep gsh | grep loader | grep -v /bin/ps | head -1 | cut -c10-15 | xar= gs` } runningUser=3D`/usr/bin/whoami` =20 # we only want appadmin or root to be able to do this if [ "$runningUser" !=3D "$shouldRunAs" ]; then =20 if [ "$runningUser" !=3D "root" ]; then =20 echo "ERROR: only user $shouldRunAs or root can run administer the grou= perLoader service: '$runningUser'" echo exit 1 =20 fi =20 fi =20 case "$1" in start) =20 gshProcessId "true" gshParentProcessId # if this is true, then it is running... if [ -n "$theGshProcessId" ]; then # lets see if the process id matches if [ -f "$pidLocation" ]; then pidInFile=3D`cat $pidLocation` =20 if [ -n "$theGshParentProcessId" ]; then if [ "$theGshParentProcessId" -eq "$pidInFile" ]; then echo "Grouper loader is running already, parent process id: $th= eGshParentProcessId, process id: $theGshProcessId" exit 1 fi fi fi echo "Grouper loader is already running, but pid doesnt match file. = Parent process id: $theGshParentProcessId, process id: $theGshProcessId, pa= rent process id in file: $pidInFile" exit 1 fi echo "Starting Grouper loader service..." # caches build up, remove them rm -rf /opt/appserv/tomcat/apps/grouperWs/logs/grouper/grouperLoaderCac= he/ehcache_auto_created_* # if not appadmin, then we must be root if [ ! "$runningUser" =3D=3D "$shouldRunAs" ]; then su $shouldRunAs -c $grouperLoaderBootstrapScript else # if not root then we must be appadmin $grouperLoaderBootstrapScript fi echo "Grouper loader is running..." ;; stop) waitingForExitStop=3Dtrue iteratorStop=3D1 wasRunning=3Dfalse while [ "$waitingForExitStop" =3D=3D "true" ]; do gshProcessId if [ -n "$theGshProcessId" ]; then wasRunning=3Dtrue echo "Grouper loader is running with processId: $theGshProcessId, w= aiting for exit..." theDate=3D`date` if [ -f $loaderLog ]; then echo >> $loaderLog echo "##############################" >> $loaderLog echo "## $theDate: stopping Grouper loader... ($theGshProcessId)"= >> $loaderLog echo "##############################" >> $loaderLog echo >> $loaderLog fi killPid $theGshProcessId else=20 waitingForExitStop=3Dfalse fi if [ "$iteratorStop" -gt "10" ]; then =20 echo "Cannot stop Grouper loader!" exit 1 fi let "iteratorStop +=3D 1" if [ "$waitingForExitStop" =3D=3D "true" ]; then sleep 1 fi done waitingForExitStop=3Dtrue iteratorStop=3D1 while [ "$waitingForExitStop" =3D=3D "true" ]; do gshParentProcessId if [ -n "$theGshParentProcessId" ]; then echo "Grouper loader parent is running with processId: $theGshProce= ssId, waiting for exit..." killPid $theGshParentProcessId else=20 waitingForExitStop=3Dfalse fi if [ "$iteratorStop" -gt "10" ]; then =20 echo "Cannot stop Grouper loader parent!" exit 1 fi let "iteratorStop +=3D 1" if [ "$waitingForExitStop" =3D=3D "true" ]; then sleep 1 fi done if [ -f $pidLocation ]; then rm $pidLocation fi if [ "true" =3D=3D "$wasRunning" ]; then echo "Grouper loader is stopped" else echo "Grouper loader was not running" fi # caches build up, remove them=20 rm -rf /opt/appserv/tomcat/apps/grouperWs/logs/grouper/grouperLoaderCac= he/ehcache_auto_created_* ;; status) gshProcessId "true" gshParentProcessId # if this is true, then it is running... if [ -n "$theGshProcessId" ]; then # lets see if the process id matches if [ -f "$pidLocation" ]; then pidInFile=3D`cat $pidLocation` =20 if [ -n "$theGshParentProcessId" ]; then if [ "$theGshParentProcessId" =3D=3D "$pidInFile" ]; then echo "Grouper loader is running, parent process id: $theGshPare= ntProcessId, process id: $theGshProcessId" exit 0 fi fi fi echo "Grouper loader is running, but pid doesnt match file. Parent p= rocess id: $theGshParentProcessId, process id: $theGshProcessId, parent pro= cess id in file: $pidInFile" exit 0 fi # lets see if the process id matches if [ -f "$pidLocation" ]; then pidInFile=3D`cat $pidLocation` =20 if [ -n "$theGshParentProcessId" ]; then echo "Grouper loader is not running, but there is a process id: $pi= dInFile in the pid file: $pidLocation" exit 1 fi fi echo "Grouper loader is not running" exit 0 ;; restart) echo -n "Restarting Grouper loader: " $0 stop sleep 5 $0 start echo "done." ;; *) echo "Usage: $0 {start|stop|restart|status}" exit 1
Set permissions and register the service:
[appadm= in@theprince grouperLoader]$ chmod +x /opt/appserv/grouperLoader/grouperLoa= der.sh [appadmin@theprince grouperLoader]$ chmod +x /opt/appserv/grouperLoader/gro= uperLoaderService.sh [root@theprince init.d]# ln -s /opt/appserv/grouperLoader/grouperLoaderServ= ice.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, gettin= g the status, etc
[appadm= in@mamapalma grouperLoader]$ ps -ef | grep gsh appadmin 14300 518 0 16:30 pts/0 00:00:= 00 grep gsh [appadmin@mamapalma grouperLoader]$ /sbin/service grouperLoader stop Grouper loader was not running [appadmin@mamapalma grouperLoader]$ /sbin/service grouperLoader status Grouper loader is not running [appadmin@mamapalma grouperLoader]$ /sbin/service grouperLoader start Starting Grouper loader service... Grouper loader is running... [appadmin@mamapalma grouperLoader]$ ps -ef | grep gsh appadmin 14420 1 0 16:30 pts/0 &nb= sp; 00:00:00 /bin/sh /opt/appserv/tomcat_3b/webapps/grouperWs/WEB-INF/bin/g= sh -loader appadmin 14421 14420 99 16:30 pts/0 00:00:09 java -Xms64m= -Xmx750m -Dgrouper.home=3D/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 14450 518 0 16:30 pts/0 00:00:= 00 grep gsh [appadmin@mamapalma grouperLoader]$ cat /opt/grouperLoader/grouperLoader.pi= d 14420 [appadmin@mamapalma grouperLoader]$ /sbin/service grouperLoader status Grouper loader is running, parent process id: 14420, process id: 14421 [appadmin@mamapalma grouperLoader]$ /sbin/service grouperLoader start Grouper loader is running already, parent process id: 14420, process id: 14= 421 [appadmin@mamapalma grouperLoader]$ echo "123" > /opt/grouperLoader/grou= perLoader.pid [appadmin@mamapalma grouperLoader]$ /sbin/service grouperLoader status Grouper loader is running, but pid doesnt match file. Parent process = id: 14420, process id: 14421, parent process id in file: 123 [appadmin@mamapalma grouperLoader]$ /sbin/service grouperLoader start Grouper loader is already running, but pid doesnt match file. Parent = process id: 14420, process id: 14421, parent process id in file: 123 [appadmin@mamapalma grouperLoader]$ ps -ef | grep gsh appadmin 14420 1 0 16:30 pts/0 &nb= sp; 00:00:00 /bin/sh /opt/appserv/tomcat_3b/webapps/grouperWs/WEB-INF/bin/g= sh -loader appadmin 14421 14420 9 16:30 pts/0 00:00:11 java -X= ms64m -Xmx750m -Dgrouper.home=3D/opt/appserv/tomcat_3b/webapps/grouperWs/WE= B-INF/bin/../ -classpath /opt/appserv/tomcat_3b/webapps/grouperWs/WEB-INF/b= in/../classes:/opt/appserv/tomcat_3b/webapps/grouperWs/WEB-INF/bin/../lib/*= : edu.internet2.middleware.grouper.app.gsh.GrouperShellWrapper -loader appadmin 14638 518 0 16:32 pts/0 00:00:= 00 grep gsh [appadmin@mamapalma grouperLoader]$ /sbin/service grouperLoader stop Grouper loader is running with processId: 14421, waiting for exit... Waiting for exit... Grouper loader is stopped [appadmin@mamapalma grouperLoader]$ ps -ef | grep gsh appadmin 14725 518 0 16:33 pts/0 00:00:= 00 grep gsh [appadmin@mamapalma grouperLoader]$ locate gsh /opt/appserv/tomcat_3b/webapps/grouperWs/WEB-INF/bin/gsh [appadmin@mamapalma grouperLoader]$ cd /opt/appserv/tomcat_3b/webapps/group= erWs/WEB-INF/bin/ [appadmin@mamapalma bin]$ ./gsh -loader & >/dev/null 2>&1 [appadmin@mamapalma bin]$ /sbin/service grouperLoader status Grouper loader is running, but pid doesnt match file. Parent process = id: , process id: 14731, parent process id in file: [appadmin@mamapalma bin]$ ps -ef | grep gsh appadmin 14731 14730 35 16:34 pts/0 00:00:10 /opt/appserv= /java6/bin/java -Xms64m -Xmx750m -Dgrouper.home=3D/opt/appserv/tomcat_3b/we= bapps/grouperWs/WEB-INF/bin/../ -classpath /opt/appserv/tomcat_3b/webapps/g= rouperWs/WEB-INF/bin/../classes:/opt/appserv/tomcat_3b/webapps/grouperWs/WE= B-INF/bin/../lib/*: edu.internet2.middleware.grouper.app.gsh.GrouperShellWr= apper -loader appadmin 14812 518 0 16:34 pts/0 00:00:= 00 grep gsh [appadmin@mamapalma bin]$ /sbin/service grouperLoader stop Grouper loader is running with processId: 14731, waiting for exit... Waiting for exit... Grouper loader is stopped [1]+ Done = ./gsh -loader [appadmin@mamapalma bin]$ ps -ef | grep gsh appadmin 14891 518 0 16:34 pts/0 00:00:= 00 grep gsh [appadmin@mamapalma bin]$ /sbin/service grouperLoader start Starting Grouper loader service... Grouper loader is running... [appadmin@mamapalma bin]$ ./gsh -loader & >/dev/null 2>&1 [appadmin@mamapalma bin]$ ps -ef | grep gsh appadmin 14956 1 0 16:35 pts/0 &nb= sp; 00:00:00 /bin/sh /opt/appserv/tomcat_3b/webapps/grouperWs/WEB-INF/bin/g= sh -loader appadmin 14957 14956 68 16:35 pts/0 00:00:10 java -Xms64m= -Xmx750m -Dgrouper.home=3D/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 14987 14986 96 16:35 pts/0 00:00:10 /opt/appserv= /java6/bin/java -Xms64m -Xmx750m -Dgrouper.home=3D/opt/appserv/tomcat_3b/we= bapps/grouperWs/WEB-INF/bin/../ -classpath /opt/appserv/tomcat_3b/webapps/g= rouperWs/WEB-INF/bin/../classes:/opt/appserv/tomcat_3b/webapps/grouperWs/WE= B-INF/bin/../lib/*: edu.internet2.middleware.grouper.app.gsh.GrouperShellWr= apper -loader appadmin 15040 518 0 16:35 pts/0 00:00:= 00 grep gsh [appadmin@mamapalma bin]$ /sbin/service grouperLoader status Grouper loader is running multiple times!!! [appadmin@mamapalma bin]$ /sbin/service grouperLoader start Grouper loader is running multiple times!!! [appadmin@mamapalma bin]$ /sbin/service grouperLoader stop Grouper loader is running with processId: 14957, waiting for exit... Waiting for exit... Grouper loader is running with processId: 14987, waiting for exit... Grouper loader is stopped [1]+ Done = ./gsh -loader [appadmin@mamapalma bin]$ ps -ef | grep gsh appadmin 15191 518 0 16:36 pts/0 00:00:= 00 grep gsh [appadmin@mamapalma bin]$