2

I have an R script that I want to have running continuously on Ubuntu 10.10. I'm trying to setup Monit to ensure that it doesn't go down. As the script starts, it creates a pid file with the lines:

pid <- max(system("pgrep -x R", intern = TRUE))
write(pid, "/var/run/myscript.pid")

Then I've set up Monit with the lines:

check process myscript with pidfile /var/run/myscript.pid
start program = "/usr/bin/R --vanilla < /home/me/myscript.R > /home/me/myscript.out 2>&1"

Monit starts fine, but when I kill the R process, the R process is not started up again. I'm obviously doing something wrong. Is it in the syntax for starting the process? I noticed that the documentation says Monit first tries to stop the programme and I don't know any commands for stopping an R process.

Perhaps of relevance is that the above line for starting the program works when it is in the crontab for the root user, but not when started from my user crontab.

Any guidance greatly appreciated.

MiG62
  • 198
  • 4
  • 10
  • 1
    Are you sure that the pid file is being created? Have you run monit in verbose mode? Are you able to use monit to stop, start, and restart the process (using monit stop/start/restart myscript)? Is the pid file readable by the monit user? I think running monit in verbose mode will be useful. – Blake Mathman Jun 28 '11 at 03:18
  • Thanks. These comments helped me solve some problems. Monit was not running due to an error elsewhere. I in fact have two scripts, one of them starts with monit start myscript -v and the pidfile is created, but the other does not and creates no pidfile. Originally I had a typo in the start command for the one that doesn't run. Now I suspect that the error is being cached somewhere because it will not start even after I have corrected it. – MiG62 Jun 29 '11 at 03:06
  • 2
    Yep. 9 times out of 10 when I have a monit issue, I find it's not a monit issue :) Good stuff, glad it's fixed. – Blake Mathman Jun 29 '11 at 03:53

1 Answers1

0

I can't comment about Monit, but there is a good article by Andrew Robinson in R News about using linux/unix tools to monitor R . In particular, screen and mail might be useful for your application.

nullglob
  • 6,903
  • 1
  • 29
  • 31
  • 1
    Thanks. Screen and mail are definitely useful tools that I can make use of, but it doesn't look like I can use them to restart a script. – MiG62 Jun 28 '11 at 13:08