Posts

Showing posts from 2015

Handling HTTPS Connection to Tomcat on AWS with AWS Load balancer

The problem You have an awesome Java app that is growing like crazy and you need to be on top of it. You will start spawning servers to scale horizontally and putting a reliable balancer in front. AWS ELB is a good one but it will not solve all your needs out of the box. You need to tweak it a little bit to fit your needs. Your app is secure, you have a SSL certificate installed but the problem is how do I redirect or force all HTTP traffic to HTTPS ? The approach Put an NGINX in each Tomcat instance. You will say.. another webserver ? yes, another one. Another point of failure but a very reliable one. Nginx is super reliable and has the smallest footprint I ever seen in a serious web server. (NodeJS is not a serious one, that is why people puts NGINX in front of it) NGINX Config NGINX will rewrite all requests to the ELB calling the HTTPS port utilizing status 301. server { listen 80; server_name myhost.com; # add ssl settings return 301 https://myhost.com$r...

Server Restart script with log e-mail

#!/bin/bash date > /tmp/v.out hostname >> /tmp/v.out /opt/jweb/ daemon /tomcat/bin/shutdown.sh >> /tmp/v.out sleep 10 /opt/jweb/ daemon /tomcat/bin/startup.sh >> /tmp/v.out dt = $(date +%d-%b-%H_%M) export msg= " Restart server @ + $(date +%d-%b-%H_%M) " test -s /tmp/v.out  && mail -s " $msg " MAIL_ID   < /tmp/v.out

Linux Custom startup and shutdown script for java or any server application

Startup: #!/bin/bash export JAVA_HOME=/usr/lib/jvm/java-8-oracle export PATH=$PATH:/$JAVA_HOME/bin cd /opt/jweb/daemon/jmsd/ #kill old instance .. just a cleanup pid=`cat ./mpid` kill $pid sleep 2 kill -9 $pid #Following lines will create file name for old log file and archiving it  n=`date +'%F_%T.out'` echo $n mv lcj.out $n gzip -9vf $n #hadoop jar lcjmsdaemon.jar 1 ./applicationContext.xml & #hadoop jar lcjmsdaemon.jar 1 > ./lcj.out 2>&1 & java -server -jar logger.jar & echo $! > ./mpid Shutdown: #!/bin/bash  cd /opt/jweb/daemon/jmsd/ pid=`cat ./mpid` kill $pid sleep 2 kill -9 $pid

Linux Upstart script for tomcat

#!/bin/bash # description: Tomcat Start Stop Restart # processname: tomcat # chkconfig: 234 20 80 #Uncomment services you would like to start  JAVA_HOME=/opt/jrockit export JAVA_HOME PATH=$JAVA_HOME/bin:$PATH export PATH TOMCAT_HOME=/opt/jweb/daemon/tomcat/bin export AMQ_HOME=/opt/jweb/daemon/amq58/bin export LCJMS_HOME=/opt/jweb/daemon/jmsd case $1 in start) /bin/su tom  -c $AMQ_HOME/startup.sh /bin/su tom  -c $TOMCAT_HOME/startup.sh #/bin/su tom  -c $LCJMS_HOME/startup.sh ;;  stop)    /bin/su tom  -c $TOMCAT_HOME/shutdown.sh ;;  restart) /bin/su tom  -c $TOMCAT_HOME/shutdown.sh /bin/su tom  -c $TOMCAT_HOME/startup.sh ;;  esac     exit 0 ## Once you create this script run following command on ubuntu to make it available on boot For Ubuntu:: # update-rc.d <scriptname> defaults For RHEL/Centos/OEL Step 1:  ...