首先,这可能需要移至超级用户.我无法确定哪个场所更好.
First of all, this may need to be moved to superuser. I couldn't decide which venue was better.
我正在尝试编写一个将在引导/重新引导时运行的R脚本,并将该计算机添加到 doRedis 工作人员. (doRedis是 foreach 后端).
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).
这是我的R脚本〜/Rworker.R"
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)我可以使用以下命令从命令行运行此脚本 sudo R CMD BATCH ~/Rworker.R ~/RLog.
I can run this script from the command line, using the command sudo R CMD BATCH ~/Rworker.R ~/RLog.
接下来,我编写了一个Shell脚本来运行R脚本,标题为"/etc/init.d/StartWorkers.sh"
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我使用chmod +x StartWorkers.sh使此Shell脚本可执行.当我运行./StartWorkers.sh时,一切正常,R会话启动,并且工作线程被添加到池中.
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.
现在,我需要这个shell脚本在启动/重新引导机器时运行,所以我键入 update-rc.d StartWorkers.sh defaults.该命令似乎可以工作,但是出现以下警告: 'update-rc.d:警告:/etc/init.d/StartWorkers.sh缺少LSB信息'
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'
但是,使用rcconf进行的检查确认"StartWorkers.R"在启动列表上.
However, a check with rcconf confirms that "StartWorkers.R" is on the startuplist.
但是,当我重新启动计算机时,脚本无法运行.我究竟做错了什么? Shell脚本可以从命令行正常运行,但是当我尝试在启动时运行它时会失败.
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.
/好的,按照Dirk的回答,我安装了littler,并将'StartWorkers.sh'更改为以下内容:
/ 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' 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!
/我必须将所有R包都移到cd /usr/lib/R/site-library,现在littler shell脚本可以工作了.我将脚本添加到/etc/rc.local,它可以完美启动!
/ 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!
推荐答案这是一个R问题,一个关于Ubuntu sysadmining问题的问题.这里有几点:
This is a bit of an R question, and a bit on an Ubuntu sysadmining question. here are a few points:
对于简单的启动任务,我建议仅使用/etc/rc.local即可在其中添加作业.
For simple start-up tasks, I recommned just using /etc/rc.local where you can append you jobs.
我只是不喜欢R CMD BATCH,这就是为什么杰夫·霍纳和我写了 littler ,可为您提供/usr/bin/r以及更简单的R脚本. R本身也给您Rscript;比R CMD BATCH更好.
I just don't like R CMD BATCH which is why Jeff Horner and I wrote littler which gives you /usr/bin/r and much easier R scripting. R itself also gives you Rscript; either one is preferable over R CMD BATCH.
要测试脚本,只需以root身份运行它们.一旦完成操作,请将其添加到/etc/rc.local.
To test scripts, just run them as root. Once theyw ork, add them to /etc/rc.local.
希望这会有所帮助. r-sig-debian列表也是Ubuntu/Debian技巧的很好来源.
Hope this helps. The r-sig-debian list is a good source of Ubuntu / Debian tips too.
更多推荐
在启动时运行R脚本
发布评论