20 мар. 2012 г.

run script

So, for many java core applications people use self made run-scripts. Most of them are some kind of sh/bash script that run java process with required arguments, classpath and so on and so on. After process is started script usually makes a pid file to track just created java process.

Many our java applications uses spring framework that's why we use Boostraper which helps us for many cases.

I do really like bash and unix-like systems,

Status brief summary:
  • current time stamp
    DATE=$(date +"%Y-%m-%d %H:%M:%S")
  • table view - easy to read, easy to check
    printf "%-42s"   "${APP_NAME}"
    printf "%-9s"    " | $(( ${PID})) "
    printf "%-9s"    " | $(( ${NO_THREADS})) "
    printf "%-20s"    "| ${START_TIME}"
    printf "%-10s\n"  "| ${STATUS}"
  • application name and its pid
  • lwps - a number of light weight processes for this application - that's java threads + jvm native threads
    ps -o nlwp -p ${PID} | tail -1
  • app start time - based on time stamp of /proc/pid/ - able to check when app was started manually or restarted on watchdog
    perl -e '@d=localtime ((stat(shift))[9]); printf "%4d%02d%02d %02d:%02d:%02d", $d[5]+1900,$d[4]+1,$d[3],$d[2],$d[1],$d[0]' /proc/${PID}
  • status - based on the quick analysis of the last line of context log file (produced by spring boostrap)

Комментариев нет: