{"id":326,"date":"2012-06-18T18:37:17","date_gmt":"2012-06-18T10:37:17","guid":{"rendered":"http:\/\/rmohan.com\/?p=326"},"modified":"2012-06-18T18:37:17","modified_gmt":"2012-06-18T10:37:17","slug":"jboss-auto-restart-script","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=326","title":{"rendered":"JBOSS AUTO RESTART SCRIPT"},"content":{"rendered":"<p><strong>JBOSS AUTO RESTART SCRIPT <\/strong><\/p>\n<p>set \u2013xv <\/p>\n<p>Shell script with Debug command inside:<\/p>\n<p>Add set \u2013xv inside the shell script now to debug the output as shown below.<\/p>\n<p>$ cat filesize.sh<br \/>\n#!\/bin\/bash<br \/>\nset -xv<br \/>\nfor filesize in $(ls -l . | grep &#8220;^-&#8221; | awk &#8216;{print $5}&#8217;)<br \/>\ndo<br \/>\n  let totalsize=$totalsize+$filesize<br \/>\ndone<br \/>\necho &#8220;Total file size in current directory: $totalsize&#8221;<\/p>\n<p>JBOSS AUTO RESTART SCRIPT <\/p>\n<p>#!\/bin\/sh<\/p>\n<p>#define where jboss is &#8211; this is the directory containing directories log, bin, conf etc<br \/>\nJBOSS_HOME=${JBOSS_HOME:-&#8220;\/apps\/appprod\/jboss-5.1.0.GA&#8221;}<\/p>\n<p>#define the user under which jboss will run, or use &#8216;RUNASIS&#8217; to run as the current user<br \/>\nJBOSS_USER=${JBOSS_USER:-&#8220;prod&#8221;}<\/p>\n<p>#make sure java is in your path<br \/>\nJAVAPTH=${JAVAPTH:-&#8220;\/usr\/java\/jdk1.6.0_31\/bin&#8221;}<\/p>\n<p>#configuration to use, usually one of &#8216;minimal&#8217;, &#8216;default&#8217;, &#8216;all&#8217;<br \/>\nJBOSS_CONF=${JBOSS_CONF:-&#8220;all&#8221;}<\/p>\n<p>#bind jboss services to a specific IP address &#8211; added by pmc<br \/>\nJBOSS_HOST=${JBOSS_HOST:-&#8220;192.168.1.55&#8243;}<\/p>\n<p>#if JBOSS_HOST specified, use -b to bind jboss services to that address<br \/>\nJBOSS_BIND_ADDR=&#8221;0.0.0.0&#8243;<br \/>\nJBOSS_BIND_ADDR=${JBOSS_HOST:+&#8221;-b $JBOSS_HOST&#8221;}<br \/>\n#JBOSS_BIND_ADDR=${JBOSS_HOST:+&#8221;$JBOSS_HOST&#8221;}<\/p>\n<p>#define the classpath for the shutdown class<br \/>\nJBOSSCP=${JBOSSCP:-&#8220;$JBOSS_HOME\/bin\/shutdown.jar:$JBOSS_HOME\/client\/jnet.jar&#8221;}<\/p>\n<p>#define the script to use to start jboss<br \/>\nJBOSSSH=${JBOSSSH:-&#8220;$JBOSS_HOME\/bin\/run.sh -c $JBOSS_CONF $JBOSS_BIND_ADDR -Djboss.service.binding.set=ports-01 -g DocsPartition1&#8221;}<\/p>\n<p>if [ &#8220;$JBOSS_USER&#8221; = &#8220;RUNASIS&#8221; ]; then<br \/>\n  SUBIT=&#8221;&#8221;<br \/>\nelse<br \/>\n  SUBIT=&#8221;su &#8211; $JBOSS_USER -c &#8221;<br \/>\nfi<\/p>\n<p>if [ -n &#8220;$JBOSS_CONSOLE&#8221; -a ! -d &#8220;$JBOSS_CONSOLE&#8221; ]; then<br \/>\n  # ensure the file exists<br \/>\n  touch $JBOSS_CONSOLE<br \/>\n  if [ ! -z &#8220;$SUBIT&#8221; ]; then<br \/>\n    chown $JBOSS_USER $JBOSS_CONSOLE<br \/>\n  fi<br \/>\nfi<\/p>\n<p>if [ -n &#8220;$JBOSS_CONSOLE&#8221; -a ! -f &#8220;$JBOSS_CONSOLE&#8221; ]; then<br \/>\n  echo &#8220;WARNING: location for saving console log invalid: $JBOSS_CONSOLE&#8221;<br \/>\n  echo &#8220;WARNING: ignoring it and using \/dev\/null&#8221;<br \/>\n  JBOSS_CONSOLE=&#8221;\/dev\/null&#8221;<br \/>\nfi<\/p>\n<p>#define what will be done with the console log<br \/>\nJBOSS_CONSOLE=${JBOSS_CONSOLE:-&#8220;\/dev\/null&#8221;}<\/p>\n<p>JBOSS_CMD_START=&#8221;cd $JBOSS_HOME\/bin; $JBOSSSH&#8221;<br \/>\n#JBOSS_CMD_STOP=${JBOSS_CMD_STOP:-&#8220;java -classpath $JBOSSCP org.jboss.Shutdown &#8211;shutdown&#8221;}<br \/>\n#JBOSS_CMD_STOP=&#8221;$JAVA_HOME\/bin\/java -classpath $JBOSSCP org.jboss.Shutdown -s jnp:\/\/$JBOSS_BIND_ADDR:1199 &#8211;shutdown&#8221;<br \/>\nJBOSS_CMD_STOP=&#8221;$JAVA_HOME\/bin\/java -classpath $JBOSSCP org.jboss.Shutdown -s jnp:\/\/$JBOSS_HOST:1199 &#8211;shutdown&#8221;<br \/>\nif [ -z &#8220;`echo $PATH | grep $JAVAPTH`&#8221; ]; then<br \/>\n  export PATH=$PATH:$JAVAPTH<br \/>\nfi<\/p>\n<p>if [ ! -d &#8220;$JBOSS_HOME&#8221; ]; then<br \/>\n  echo JBOSS_HOME does not exist as a valid directory : $JBOSS_HOME<br \/>\n  exit 1<br \/>\nfi<\/p>\n<p>echo JBOSS_CMD_START = $JBOSS_CMD_START<\/p>\n<p>case &#8220;$1&#8221; in<br \/>\nstart)<br \/>\n    cd $JBOSS_HOME\/bin<br \/>\n    if [ -z &#8220;$SUBIT&#8221; ]; then<br \/>\n        eval $JBOSS_CMD_START >${JBOSS_CONSOLE} 2>&#038;1 &#038;<br \/>\n    else<br \/>\n        $SUBIT &#8220;$JBOSS_CMD_START >${JBOSS_CONSOLE} 2>&#038;1 &#038;&#8221;<br \/>\n    fi<br \/>\n    ;;<br \/>\nstop)<br \/>\n    if [ -z &#8220;$SUBIT&#8221; ]; then<br \/>\n        $JBOSS_CMD_STOP<br \/>\n    else<br \/>\n        $SUBIT &#8220;$JBOSS_CMD_STOP&#8221;<br \/>\n    fi<br \/>\n    ;;<br \/>\nrestart)<br \/>\n    $0 stop<br \/>\n    $0 start<br \/>\n    ;;<br \/>\n*)<br \/>\n    echo &#8220;usage: $0 (start|stop|restart|help)&#8221;<br \/>\nesac<\/p>\n","protected":false},"excerpt":{"rendered":"<p>JBOSS AUTO RESTART SCRIPT <\/p>\n<p>set \u2013xv <\/p>\n<p>Shell script with Debug command inside:<\/p>\n<p>Add set \u2013xv inside the shell script now to debug the output as shown below.<\/p>\n<p>$ cat filesize.sh #!\/bin\/bash set -xv for filesize in $(ls -l . | grep &#8220;^-&#8221; | awk &#8216;{print $5}&#8217;) do let totalsize=$totalsize+$filesize done echo &#8220;Total file [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/326"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=326"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/326\/revisions"}],"predecessor-version":[{"id":327,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/326\/revisions\/327"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=326"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=326"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=326"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}