On Fri, 2002-10-11 at 12:48, camccuk wrote:
> --- Ben Ricker <[EMAIL PROTECTED]> wrote:
> I'b be interested to see that Ben - one of the problems I had trying something
> similar was that when tomcat gets swapped out, it appears on the process list
> as [java] and there is *no way* to my knowledge (or that of the various usenet
> groups/lists etc that I pestered) of getting back the command line to see which
> instance of the JVM you are dealing with - this was a problem for me on a
> machine running at least two JVMs.
Actually there is. I use a -Dafoo to give the process a unique
identifier. This sets a marker on the process but does nothing for the
JVM itself. To find a process ID, I would use 'pgrep -f foo' and the PID
is returned (this is on Unix, btw). Also , when you do the '-Dafoo' as
the first "arg" to the JVM, it appears in 'ps -ef'.
Here is how I do it: I setup the java command line like so:
/usr/local/jdk/bin/java \
-Da=Ftp \
-cp $PROP_DIR:$EXT_INT_JAR:$NET_COMPONENTS_JAR:$LOG4J_JAR \
com.usrx.extinterface.ftp.FTPService $PROPERTIES_FILES \
>> $LOG_FILE 2>&1
Then I do this:
pgrep -fn Ftp > $PIDFILE
Technically, you do not need the 'n', as that denotes the newest
process. You can get by with just the -f.
Finally, I run the following script through cron every minute. The
variables should be self-explanatory. For security reasons, I cannot
divulge the whole setup. Basically, this snippet below monitors 7 JVMs
and if they are not running, restarts them. It has worked flawlessly for
a long time.
-----Begin Snippet------
for i in $*
do
eval BASEDIR=$`echo BASEDIR_$i`
eval PIDFILE="$BASEDIR/$`echo PIDFILE_$i`"
eval PNAME=$`echo PNAME_$i`
eval CHECKFILE="$BASEDIR/$`echo CHECKFILE_$i`"
eval START="$BASEDIR/$`echo START_$i`"
if [ -f $PIDFILE ] ; then
PID=`cat $PIDFILE`
if [ "x$PID" != "x" ] && kill -0 $PID 2>/dev/null ; then
STATUS="$PNAME ($PID) running"
RUNNING=1
else
STATUS="$PNAME ($PID?) NOT running"
RUNNING=0
fi
else
STATUS="$PNAME (no pid file) NOT running"
RUNNING=0
fi
if [ $RUNNING = 0 ]; then
if [ -f $CHECKFILE ] ; then
if [ `cat $CHECKFILE` = 0 ] ; then
echo "$STATUS - restart failed." | mail -s "$PNAME alert" $RECIPIENTS
logger -p local0.crit -t pidmonitor.sh "$STATUS: restart failed."
echo "1" > $CHECKFILE
fi
cd $BASEDIR
$START start
else
echo "$STATUS - will attempt to start." | mail -s "$PNAME alert"
$RECIPIENTS
logger -p local0.crit -t pidmonitor.sh "$STATUS: attempting to start."
touch $CHECKFILE
echo "0" > $CHECKFILE
cd $BASEDIR
$START start
fi
else
if [ -f $CHECKFILE ] ; then
/bin/rm $CHECKFILE
echo "$STATUS" | mail -s "$PNAME alert" $RECIPIENTS
logger -p local0.crit -t pidmonitor.sh $STATUS
fi
fi
done
------End Snippet------
> I had to use fghack already to stop supervise trying to start tomcat dozens of
> time but I still couldn't get multilog to work and supervise seemed to act
> weirdly afterwards (although svstat worked ok and svscan got into a confused
> state trying to start the run script in the logging subdirectory - something
> supervise won't do for me)
You will have to use fghack because java does not act like a daemon
usually does. A daemon usually puts itself into the background after
executing. Java does not. That is what fghack does. Unfortunately, as
the web site for daemontools says, if you use fghack, it will disable
your ability to use svc and will make all the other commands pretty
useless. Daemontools works great with daemons that act like daemons; it
works like hell with programs that don't.
--
Ben Ricker <[EMAIL PROTECTED]>
Wellinx.com
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>