I have monit utility on production for monitoring several daemons (our micro-services). I'm trying to figure the best way to unmonitor/monitor my daemons while updating them. So, basically I need something like this, pseudo-code:
has_monit = false if `monit watches daemon-xxx` then has_monit = true monit unmonitor daemon-xxx endif apt-get install xxx.deb if has_monit then monit monitor deamon-xxx endif Unfortunately it seems that monit summary daemon-xxx is always return exit code 0 regardless it was success or failure, and prints raw html about failure, e.g.
[bialix@server ~]$ sudo monit summary xxx <html><head><title>400 Bad Request</title></head><body bgcolor=#FFFFFF><h2>Bad Request</h2>Service 'xxx' not found<hr><a href='http://mmonit.com/monit/'><font size=-1>monit 5.30.0</font></a></body></html> [bialix@server ~]$ echo $? 0 It seems exit code 1 only if monit is not running.
What is the right way here? Parsing the output of monit summary?