[英]Run rake outside of rails_root/Incron doesn't run rake or bundle commands for rails
我在/ home / myuser / watchDir / myapp中有一个rails应用程序,并且有一个incron作业设置来监视../watchDir进行修改。 触发后,incron将运行脚本/usr/local/bin/myscript.sh。 这是我可以让incron从中运行脚本的唯一地方。 在该脚本中,我有调用以在根应用程序中运行rake
和bundle
命令。 I脚本正在运行(对此有一个测试),但是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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.