I have installed GeoSerer running with Jetty. I use monit to monitor GeoServer is running or not and I need pid in the process.
Anyone can tell me how to do that?
I have installed GeoSerer running with Jetty. I use monit to monitor GeoServer is running or not and I need pid in the process.
Anyone can tell me how to do that?
supposing you are using the default startup/shutdown scripts, the quick and dirty way is:
gsrvpid=`ps axuwwwww|grep GEOSERVER | grep -v grep | awk ' { print $2 ; } '`
echo $gsrvpid
25271
(i just grepped for a pattern that should match only the process I am interested in but you may get weird results if the pattern matches something else as well)
the correct way is to wrap the startup/shutdown scripts into a init script that will save the pid somewhere in the file system cuz as we can notice the java dudes don't really care about providing good service management scripts.
startup script (very simplified):
#!/bin/sh
export GEOSERVER_HOME=/root/tmp/geoserver-2.0.2
cd ${GEOSERVER_HOME} || exit
echo $$ > /var/run/geoserver.pid
exec ./bin/startup.sh
shutdown script (very simplified):
#!/bin/sh
export GEOSERVER_HOME=/root/tmp/geoserver-2.0.2
cd ${GEOSERVER_HOME} || exit
./bin/shutdown.sh
rm -f /var/run/geoserver.pid
you can get the pid of the process with
cat /var/run/geoserver.pid
like this:
ps www -p `cat /var/run/geoserver.pid`
PID TTY STAT TIME COMMAND
26394 pts/4 Sl+ 0:12 /usr/lib/jvm/java-6-sun/bin/java -DGEOSERVER_DATA_DIR=/root/tmp/geoserver-2.0.2/data_dir -Djava.awt.headless=true -DSTOP.PORT=8079 -DSTOP.KEY=geoserver -jar start.jar
or like this:
kill -0 `cat /var/run/geoserver.pid` && echo "my geo thing is alive"
my geo thing is alive