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