ruby-on-rails - 在 rails_root/Incron 之外运行 rake 不会为 rails 运行 rake 或 bundle 命令

标签 ruby-on-rails linux bash rake-task incron

我在/home/myuser/watchDir/myapp 中有一个 Rails 应用程序和一个 incron 作业集来监视 ../watchDir 进行修改。一旦触发,incron 将运行脚本/usr/local/bin/myscript.sh。这是我唯一可以让 incron 运行脚本的地方。在该脚本中,我调用了在我的根应用程序中运行 rakebundle 命令的命令。我正在运行脚本(我对此进行了测试),但 bundlerake 命令均无提示地失败。我是 linux 的新手,互联网研究提供了一些解决方案。我的脚本中有所有绝对路径。我尝试将我的 bash_profile 添加到 scripts/incron 命令中。我尝试让 incron 脚本运行位于我的主目录中的另一个脚本。所有脚本都是可执行的。我尝试对 bundle 使用 --gemfile 选项,但这不起作用。有谁知道我必须在这里做什么?基本上,我想在 RAILS_ROOT 之外运行 bundlerake 命令。我还想知道 incron 是否会使 rails 命令的使用复杂化。谢谢。

编辑:

相关文件如下:

Incrontab:

/home/myuser/watchDir/ IN_MODIFY,IN_CLOSE_WRITE,IN_CLOSE_NOWRITE /bin/bash /usr/local/bin/runT.sh  $@/$#

我也试过这个:

/home/myuser/watchDir/ IN_MODIFY,IN_CLOSE,IN_CLOSE_WRITE,IN_CLOSE_NOWRITE source '/home/myuser/.bash_profile && /bin/sh /usr/local/bin/runT.sh'  $@/$#

这是它调用的脚本:

#!/bin/bash
mkdir /home/myuser/worked  #This is to ensure that that incron is running and executing this script
cd /home/myuser/watchDir/myapp
/home/myuser/.rvm/gems/ruby-1.9.3-p545/bin/bundle install --gemfile /home/myuser/watchDir/myApp/Gemfile
/home/myuser/.rvm/gems/ruby-1.9.3-p545/bin/rake -f /home/myUser/watchDir/myApp

我的 .bash_profile 文件:

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
source ~/.profile

最佳答案

总结一下我最后的评论...将您的 icrontab 条目更改为:

/home/myuser/watchDir/ IN_MODIFY,IN_CLOSE_WRITE,IN_CLOSE_NOWRITE /bin/bash /usr/local/bin/runT.sh  $@/$#

脚本是:

#!/bin/bash
source /home/myuser/.bash_profile
mkdir /home/myuser/worked  #This is to ensure that that incron is running and executing this script
cd /home/myuser/watchDir/myapp
/home/myuser/.rvm/gems/ruby-1.9.3-p545/bin/bundle install --gemfile /home/myuser/watchDir/myApp/Gemfile
#/home/myuser/.rvm/gems/ruby-1.9.3-p545/bin/rake -f /home/myUser/watchDir/myApp

关于ruby-on-rails - 在 rails_root/Incron 之外运行 rake 不会为 rails 运行 rake 或 bundle 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22389323/

相关文章:

c - Waitpid 函数中的 WNOHANG 宏

regex - 冯内古蒂命令 : Replace semicolons with periods *correctly*

bash - 在进行 ffmpeg 转换时将元数据值转换为字符串

ruby-on-rails - 如何使用Searchkick和Rails处理嵌套文档?

ruby-on-rails - assert_not_in_array

python - Yocto,安装 Numpy

linux - Chromium 浏览器的进程 ID 未显示在终端中

bash - 如果文件中不包含字符串,如何将其附加到文件?

ruby-on-rails - Ruby on Rails 3 以及如何制作 Web 服务

ruby-on-rails - 在 Rails 中按属性查找多个数据库对象?