java - Monitor shell script with monit -
i have shell script spawns java process i'd wrap in wrapper use monit.
i've tried monit recommendation of
#!/bin/bash name=`basename $1` case $2 in start) echo $$ > /var/run/service.pid; exec 2>&1 $1 1>/var/log/$name.stdout ;; stop) kill `cat /var/run/service.pid` ;; *) echo "usage: <path app> {start|stop}" ;; esac
where i'd use wrapper.sh /usr/sbin/cmd start
when this, see 2 procesess spun up. 1 exec in wrapper, , other java process.
however, pid of $$
of /usr/sbin wrapper , not of actual java process. if "stop" service or kill pid, java process gets orphaned.
on other hand, if run /usr/sbin/cmd
in foreground , kill it, kill child process.
you can't grab pid before run command, can use $!
. also, suggest use nohup
. like
nohup $1 > /var/log/$name.stdout 2>&1 & echo $! > /var/run/service.pid
Comments
Post a Comment