Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- (
- # we need to close all existing file descriptors, because
- # JVM passes them all on fork, and we end up holding up
- # listening sockets, causing re-use failure on tomcat startup
- # https://unix.stackexchange.com/questions/123413/close-all-file-descriptors-in-bash
- for fd in $(ls /proc/$$/fd); do
- case "$fd" in
- 0|1|2)
- ;;
- *)
- eval "exec $fd>&-"
- ;;
- esac
- done
- if test "$1" != setsid; then
- date; echo "Invoked with pid $1, restarting ourselves"
- setsid $0 setsid $1 &
- exit 0
- fi
- `dirname $0`/shutdown.sh
- date; echo "Shutdown called"
- java="$2"
- date; echo "Waiting for $java to die"
- laps=200
- while test -e /proc/$java; do
- sleep 0.1
- laps=$((laps-1))
- # if shutdown failed to stop the server,
- # we must kill it, but this may leave
- # open ports, so we delay ourselve for
- # some time.
- test $laps -eq 0 && {
- date; echo "Waited too long, killing"
- kill -9 $java
- sleep 120
- break;
- }
- done
- date; echo "About to restart the server"
- # You can send an email, or some other notification here
- # Mail -s "Tomcat restarted due to OOM" << _EOF_
- # Tomcat PID $java has been restarted due to OOM
- # _EOF_
- # sleeping for a while for process to die for sure
- sleep 5
- # this script is expected to be at bin directory
- # of the corresponding tomcat. If not, change the path
- date; echo "Calling startup.."
- `dirname $0`/startup.sh
- ) >> /tmp/restart.log 2>&1
Advertisement
Add Comment
Please, Sign In to add comment