2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux#!/bin/sh
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux
dd7622f51012ac1dcc8c132417d45997121d46abJim MitchenerPRGDIR=$(dirname $0)
dd7622f51012ac1dcc8c132417d45997121d46abJim Mitchener
dd7622f51012ac1dcc8c132417d45997121d46abJim Mitchenercd $PRGDIR/..
dd7622f51012ac1dcc8c132417d45997121d46abJim Mitchener
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael AlliouxOPENIDM_HOME=`pwd`
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael AlliouxOPENIDM_USER=`id -un`
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael AlliouxSCRIPT_NAME='openidm'
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael AlliouxJAVA_BIN=`which java`
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux#########################################
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Alliouxcat << EOF > bin/${SCRIPT_NAME}
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux#!/bin/sh
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux# chkconfig: 345 95 5
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux# description: start/stop openidm
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux# clean up left over pid files if necessary
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael AlliouxcleanupPidFile() {
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux if [ -f \$OPENIDM_PID_FILE ]; then
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux rm -f "\$OPENIDM_PID_FILE"
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux fi
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux trap - EXIT
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux exit
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux}
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael AlliouxJAVA_BIN=${JAVA_BIN}
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael AlliouxOPENIDM_HOME=${OPENIDM_HOME}
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael AlliouxOPENIDM_USER=${OPENIDM_USER}
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael AlliouxOPENIDM_PID_FILE=\$OPENIDM_HOME/.openidm.pid
4c8a0a5b93bca43d2d6912bb3954c54ccc1f8bb2Jake FeaselOPENIDM_OPTS="${OPENIDM_OPTS}"
4c8a0a5b93bca43d2d6912bb3954c54ccc1f8bb2Jake Feasel
4c8a0a5b93bca43d2d6912bb3954c54ccc1f8bb2Jake Feasel# Only set OPENIDM_OPTS if not already set
4c8a0a5b93bca43d2d6912bb3954c54ccc1f8bb2Jake Feasel[ -z "$OPENIDM_OPTS" ] && OPENIDM_OPTS="${openidm.options} -Dfile.encoding=UTF-8"
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Alliouxcd \${OPENIDM_HOME}
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux# Set JDK Logger config file if it is present and an override has not been issued
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Alliouxif [ -z "\$LOGGING_CONFIG" ]; then
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux if [ -r "\$OPENIDM_HOME"/conf/logging.properties ]; then
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux LOGGING_CONFIG="-Djava.util.logging.config.file=\$OPENIDM_HOME/conf/logging.properties"
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux else
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux LOGGING_CONFIG="-Dnop"
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux fi
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Alliouxfi
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux
0dc6ca068edfdc2f0ab6b806f81cb128569f25baGael AlliouxCLASSPATH="\$OPENIDM_HOME"/bin/*
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux
0dc6ca068edfdc2f0ab6b806f81cb128569f25baGael Allioux
0dc6ca068edfdc2f0ab6b806f81cb128569f25baGael AlliouxSTART_CMD="nohup \$JAVA_BIN \$LOGGING_CONFIG \$JAVA_OPTS \$OPENIDM_OPTS \\
0dc6ca068edfdc2f0ab6b806f81cb128569f25baGael Allioux -Djava.endorsed.dirs=\$JAVA_ENDORSED_DIRS \\
0dc6ca068edfdc2f0ab6b806f81cb128569f25baGael Allioux -classpath \\"\$CLASSPATH\\" \\
0dc6ca068edfdc2f0ab6b806f81cb128569f25baGael Allioux -Djava.awt.headless=true \\
f09aea65bda59081d8f875c76a03762df5fb41c2Tom Wood -Dopenidm.system.server.root=\$OPENIDM_HOME \\
0dc6ca068edfdc2f0ab6b806f81cb128569f25baGael Allioux org.forgerock.commons.launcher.Main -c bin/launcher.json > logs/server.out 2>&1 &"
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Alliouxcase "\${1}" in
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Alliouxstart)
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux su \$OPENIDM_USER -c "\$START_CMD eval echo \\$\! > \$OPENIDM_PID_FILE"
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux exit \${?}
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux ;;
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Alliouxstop)
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux ./shutdown.sh > /dev/null
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux exit \${?}
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux ;;
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Alliouxrestart)
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux ./shutdown.sh > /dev/null
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux su \$OPENIDM_USER -c "\$START_CMD eval echo \\$\! > \$OPENIDM_PID_FILE"
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux exit \${?}
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux ;;
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux*)
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux echo "Usage: ${SCRIPT_NAME} { start | stop | restart }"
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux exit 1
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux ;;
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Alliouxesac
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael AlliouxEOF
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux#########################################
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Alliouxchmod a+x bin/${SCRIPT_NAME}
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Allioux
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Alliouxecho
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Alliouxecho "${SCRIPT_NAME} script has been created in ${OPENIDM_HOME}/bin"
863815476e3f68ca0d4768d6731f74810d87aee6Mike Jangecho "To finish installation, copy the script to the /etc/init.d folder"
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Alliouxecho "and run the following command:"
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Alliouxecho "chkconfig --add openidm"
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Alliouxecho
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Alliouxecho "To remove the service, run the following command:"
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Alliouxecho "chkconfig --del openidm"
2b76baf9f9173340ad9d52affcec8bdb1e1ae5edGael Alliouxecho