Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.