Hi,
see monit FAQ - example:
3. Q: I have a program that does not create its own pid file. Since
monit requires all programs to have a pid file, what do I do?
A: Create a wrapper script and have the script create a pid file
before it starts the program. Below you will find an example
script for starting an imaginary program (a Java program in this
case). Assuming that the script is saved in a file called
/bin/xyz, you can call this script from monit by using the
following in monitrc:
check process xyz with pidfile /tmp/xyz.pid
start = "/bin/xyz start"
stop = "/bin/xyz stop"
--8<--- (cut here)
#!/bin/bash
export JAVA_HOME=/usr/local/java/
export DISPLAY=localhost:0.0
CLASSPATH=ajarfile.jar:.
case $1 in
start)
echo $$ > /tmp/xyz.pid;
exec 2>&1 java -cp ${CLASSPATH} org.something.with.main \
1>/tmp/xyz.out
;;
stop)
kill `cat /tmp/xyz.pid` ;;
*)
echo "usage: xyz {start|stop}" ;;
esac
--8<---- (cut here)
Martin