[svlug] Why script not run correctly as a service
Tomer
tomer at pacbell.net
Tue Sep 23 09:23:14 PDT 2008
Hi All,
A question for the bash/Linux experts out there. I have a script shown below
that ensures that tomcat on port 8081 is always running. I noticed that when
running this as a service (by putting a link to it in /etc/init.d and adding
it using chkconfig) it does run when the system reboots, however, when
tomcat goes down, it does not restart it (the TOMCATSTART command does
nothing)
HOWEVER, if running this script from root login as
nohup ymca_watchdog.sh &
It DOES restart tomcat when it goes down. Specifically, I noticed that if I
reboot the machine and let the service run it does nothing when tomcat is
down. However, if I start the script manually /etc/init.d/ymca_watchdog.sh
and then logout it works ok.
What is the difference between these two run methods that cause it not to
work in one and do work in the other? Here is the script below:
=====================================
#!/bin/bash
PGMDIR="/root/watchdog"
TOMCATSTART="/root/tomcattools/tmcatstrt2.sh"
TOMCATSTOP="/root/tomcattools/tmcatstp2.sh"
WPORT=8081
if [ ! -d $PGMDIR ]; then
mkdir "$PGMDIR"
fi
while true; do
echo "$(date): Checking HTTP on port $WPORT..." >> "$PGMDIR/log.txt"
if wget -q -nc localhost:$WPORT ; then
echo "$(date): ymca watchdog - all good" >>"$PGMDIR/log.txt"
else
$TOMCATSTOP
sleep 2
$TOMCATSTART
echo "$(date): attempted to restart tomcat" >>
"$PGMDIR/log.txt"
fi
echo "$(date): Sleeping for 2 minutes..." >> "$PGMDIR/log.txt"
sleep 120
done
AND HERE IS /root/tomcattools/tmcatstrt2.sh :
#!/bin/sh
JAVA_HOME=/usr/local/jdk
export JAVA_HOME
/usr/local/tomcat2/bin/startup.sh
-----Original Message-----
From: svlug-bounces+tomer=pacbell.net at lists.svlug.org
[mailto:svlug-bounces+tomer=pacbell.net at lists.svlug.org] On Behalf Of
svlug-request at lists.svlug.org
Sent: Saturday, September 20, 2008 12:00 PM
To: svlug at lists.svlug.org
Subject: svlug Digest, Vol 337, Issue 25
Send svlug mailing list submissions to
svlug at lists.svlug.org
To subscribe or unsubscribe via the World Wide Web, visit
http://lists.svlug.org/lists/listinfo/svlug
or, via email, send a message with subject or body 'help' to
svlug-request at lists.svlug.org
You can reach the person managing the list at
svlug-owner at lists.svlug.org
When replying, please edit your Subject line so it is more specific than
"Re: Contents of svlug digest..."
More information about the svlug
mailing list