bash - Monit fails to start process -
i've written scrip works fine start , stop server.
#!/bin/bash pid_file='/var/run/rserve.pid' start() { touch $pid_file eval "/usr/bin/r cmd rserve" pid=$(ps aux | grep rserve | grep -v grep | awk '{print $2}') echo "starting rserve pid $pid" echo $pid > $pid_file } stop () { pkill rserve rm $pid_file echo "stopping rserve" } case $1 in start) start ;; stop) stop ;; *) echo "usage: rserve {start|stop}" ;; esac exit 0
if start running
rserve start
and start monit
correctly capture pid , server:
the monit daemon 5.3.2 uptime: 0m remote host 'localhost' status online services monitoring status monitored port response time 0.000s localhost:6311 [default via tcp] data collected mon, 13 may 2013 20:03:50 system 'system_gauss' status running monitoring status monitored load average [0.37] [0.29] [0.25] cpu 0.0%us 0.2%sy 0.0%wa memory usage 524044 kb [25.6%] swap usage 4848 kb [0.1%] data collected mon, 13 may 2013 20:03:50
if stop it, kill process , unmonitor it. if start again, won't start server again:
ps ax | grep rserve | grep -vc grep 1 monit stop localhost ps ax | grep rserve | grep -vc grep 0 monit start localhost [utc may 13 20:07:24] info : 'localhost' start on user request [utc may 13 20:07:24] info : monit daemon @ 4370 awakened [utc may 13 20:07:24] info : awakened user defined signal 1 [utc may 13 20:07:24] info : 'localhost' start: /usr/bin/rserve [utc may 13 20:07:24] info : 'localhost' start action done [utc may 13 20:07:34] error : 'localhost' failed, cannot open connection inet[localhost:6311] via tcp
here monitrc:
check host localhost address 127.0.0.1 start = "/usr/bin/rserve start" stop = "/usr/bin/rserve stop" if failed host localhost port 6311 type tcp timeout 15 seconds 5 cycles restart
i had problem start or stop process via shell too. 1 solution might add "/bin/bash" in config this:
start program = "/bin/bash /urs/bin/rserv start" stop program = "/bin/bash /urs/bin/rserv stop"
it worked me.
Comments
Post a Comment