First of all, this may need to be moved to superuser. I couldn't decide which venue was better.
I am trying to write an R script that will run at boot/reboot and add that machine to a pool of doRedis workers. (doRedis is a foreach backend).
Here is my R script, "~/Rworker.R"
#Define Parameters
require(multicore)
Host <- 'ip_of_doRedis_Server'
cores <- multicore:::detectCores()
TO <- 24*3600
#Start Workers
require('doRedis')
startLocalWorkers(cores,'jobs',host=Host,port=6379, timeout = TO)
I can run this script from the command line, using the command
sudo R CMD BATCH ~/Rworker.R ~/RLog
.
Next, I wrote a shell script to run the R script, titled "/etc/init.d/StartWorkers.sh"
#!/bin/sh
sudo echo "Starting R workers"
sudo R CMD BATCH ~/Rworker.R ~/RLog
I made this shell script executable, using chmod +x StartWorkers.sh
. When I run ./StartWorkers.sh
everything works great and the R session starts up and the workers get added to the pool.
Now, I need this shell script to run when I boot/reboot the machine, so I type
update-rc.d StartWorkers.sh defaults
. This command appears to work, but I get the following warning:
'update-rc.d: warning: /etc/init.d/StartWorkers.sh missing LSB information'
However, a check with rcconf confirms that "StartWorkers.R" is on the startuplist.
However, when I reboot the machine, the script fails to run. What am I doing wrong? The shell script runs fine from the command line, but fails when I try to run it at startup.
/EDIT: ok, per Dirk's answer, I installed littler, and changed 'StartWorkers.sh' to the following:
#! /usr/bin/r
#Define Parameters
require(multicore)
Host <- 'zachec2.dyndns.org'
cores <- multicore:::detectCores()
TO <- 24*3600
#Start Workers
require('doRedis')
startLocalWorkers(cores,'jobs',host=Host,port=6379, timeout = TO)
But when I run it, I get the following output:
Loading required package: utils
Loading required package: multicore
Warning message:
In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
there is no package called 'multicore'
Error in loadNamespace(name) : there is no package called 'multicore'
Calls: ::: ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
Execution halted
I know I have multicore installed on my system!
/EDIT2: I had to move all my R packages to cd /usr/lib/R/site-library
and now the littler shell script works. I added the script to /etc/rc.local
and it starts up perfectly!