# tomcat-launchd.sh # # Wrapper script that starts Tomcat and waits for the Tomcat process # to exit. This is needed for proper interaction with launchd.
# NOTE: We are inheriting CATALINA_HOME from launchd, because its value # was defined in the launchd plist configuration file.
functionshutdown() { # Bye Tomcat! echo "Shutting down Tomcat... " $CATALINA_HOME/bin/catalina.sh stop echo "done." # Cleaning up the temporary file rm -f $CATALINA_PID }
functionstartup() { # Define the file where we want the Tomcat process ID to be stored. export CATALINA_PID=$(mktemp /tmp/\`basename -s .sh $0\`.XXXXXX) if \[ $? -ne 0 \] then echo "$0: Failed to create temporary file. Aborting." exit 1 fi rm -f $CATALINA_PID # Let's go! echo "Starting up Tomcat... " . $CATALINA_HOME/bin/catalina.sh start # Register the shutdown function as callback to execute when a signal # is sent to this process. #捕捉以下信号使tomcat关闭 trap shutdown HUP INT QUIT ABRT KILL ALRM TERM TSTP echo "done." } function wait_for_tomcat_to_exit() { echo "Waiting for Tomcat to exit (PID: \`cat $CATALINA_PID\`)... " #等待tomcat进程退出 wait \`cat $CATALINA_PID\` echo "done waiting for Tomcat to exit." } #--------------------------------------------------------- # Let's go #--------------------------------------------------------- startup wait_for_tomcat_to_exit