Debugging monit

后端 未结 7 2037
迷失自我
迷失自我 2020-12-07 09:04

I find debugging monit to be a major pain. Monit\'s shell environment basically has nothing in it (no paths or other environment variables). Also, there are no log file that

7条回答
  •  感动是毒
    2020-12-07 09:28

    Yeah monit isn't too easy to debug.

    Here a few best practices

    • use a wrapper script that sets up your log file. Write your command arguments in there while you are at it:

    shell:

    #!/usr/bin/env bash
    
    logfile=/var/log/myjob.log
    touch ${logfile} 
    echo $$ ": ################# Starting " $(date) "########### pid " $$ >> ${logfile}
    
    echo "Command: the-command $@" >> ${logfile} # log your command arguments
    {
      exec the-command $@
    } >> ${logfile} 2>&1
    

    That helps a lot.

    The other thing I find that helps is to run monit with '-v', which gives you verbosity. So the workflow is

    • get your wrapper working from the shell "sudo my-wrapper"
    • then try and get it going from monit, run from the command line with "-v"
    • then try and get it going from monit, running in the background.

提交回复
热议问题