Quantcast
Channel: Technical Blog for Software Enthusiasts
Viewing all articles
Browse latest Browse all 26

Tomcat - Setup and Run Secondary Instance - Final Part

$
0
0

Stopping is quite easy and you must be knowing it already what needs to be done to stop the secondary instance of tomcat. Yes, we just delete the iptables redirection rules and then stop the instance.

But before doing that we should be checking whether our primary instance is running properly. Otherwise our website users would be left high and dry. Going through all this song and dance of performing "Zero Downtime" deployment would come to nought.

In every profession user / customer is the king and software is no exception. As a software professional the single most important responsibility we have is to care for our users and let us not shirk it.

At hudku.com we just do a simple check to see whether the AJP port 8009 is open and if not we abort and do not proceed further.

If you desire, you can refer to the previous script and use functions like isProcessRunning() and getHTTPResponseStatus() to further ascertain the health of the primary tomcat instance.

Once it is verified that the primary tomcat instance is indeed running properly, the script proceeds further, removes the iptables redirection rules first and then stops the secondary tomcat instance.

This brings us to the conclusion of the topic "Setup and Run Secondary Tomcat Instance". Same code can be used to setup and run multiple tomcat instances and the scripts can be used on any linux machine.

You can download the zip file containing the complete collection of scripts for setting up and running secondary tomcat instance here.

Here is the source code of the script "tomcat-stop-secondary.sh" to stop the secondary tomcat instance.
#!/bin/bash # Execute "export DEBUG=1" to debug this script. # Set value to 2 to debug this script and the scripts called within this script. # Set value to 3,4,5 and so on to increase the nesting level of the scripts to be debugged. [[ $DEBUG -gt 0 ]] && set -x; export DEBUG=$(($DEBUG - 1)) # # Stop the secondary instance # tomcatSecondaryInstanceName="$TOMCAT_SECONDARY_INSTANCE_NAME" # include all the utility scripts source $ELASTICBEANSTALK_APP_SCRIPT_DIR/include/include.sh if ( ! $(isPortOpen 8009) ) then echo -e "Error: Tomcat primary instance port 8009 is not open. Please check.\n" exit 1 fi # Remove the internal port redirections iptables -D OUTPUT -t nat -p tcp -d 127.0.0.1 --dport 8080 -j REDIRECT --to-port 8180 iptables -D OUTPUT -t nat -p tcp -d 127.0.0.1 --dport 8009 -j REDIRECT --to-port 8109 iptables -D OUTPUT -t nat -p tcp -d 127.0.0.1 --dport 8443 -j REDIRECT --to-port 8543 # Stop the secondary instance service $tomcatSecondaryInstanceName stop if ([ $? -ne 0 ]) then echo "Error: Failed to stop the tomcat secondary instance $tomcatSecondaryInstanceName" exit 1 fi echo "Secondary tomcat instance $tomcatSecondaryInstanceName stopped successfully"

Viewing all articles
Browse latest Browse all 26

Trending Articles