2

On my server I have started a service using a script created by myself.
I want to monitor that process using monit. I didn't see any .pid file for that process in the /var/run directory. How can I monitor that process using monit?

ewwhite
  • 194,921
  • 91
  • 434
  • 799
  • If the missing pid file is your only problem, capture the process ID in your start-up script and create the pid file there? – HBruijn Oct 16 '14 at 11:00
  • it was a java service.when i starting the script one of the maven plugin ececute.thats my process. when i check ps -aux,i see the process with a pid.but didnt see a .pid file.how can i create a .pid file for that?? – user3793677 Oct 16 '14 at 11:18
  • [Capture the process ID](http://stackoverflow.com/questions/4339756/inside-a-bash-script-how-to-get-pid-from-a-program-executed-when-using-the-eval) and echo that number to the pid file ; in essence that's it. – HBruijn Oct 16 '14 at 11:33
  • HOw can i set mail alert for this process... – user3793677 Oct 20 '14 at 07:20

1 Answers1

1

Remember, it is possible to use Monit to manage a process that does not have a PID file. In newer versions of the utility (which you should have) you can leverage the matching directive to check the name of your script. If it's running, try using the monit procmatch yourscriptname command, i.e.:

# monit procmatch orca
List of processes matching pattern "orca":
------------------------------------------
    /usr/bin/perl -w # -*- perl -*- /usr/local/bin/orca -d procallator.cfg
------------------------------------------
Total matches: 1

Keep in mind that monit only tracks the first instance it finds using the procmatch filter.
Your monit code would look something like this:

check process myprocessname
        matching "myprocessname"
        start program = "/etc/init.d/myproccessname start"
        stop program = "/usr/bin/killall myprocessname"
        if cpu usage > 95% for 10 cycles then restart

Also see: monit: check process without pidfile

ewwhite
  • 194,921
  • 91
  • 434
  • 799