[英]Run rake outside of rails_root/Incron doesn't run rake or bundle commands for rails
I have a rails application in /home/myuser/watchDir/myapp and an incron job set to watch the ../watchDir for modification. 我在/ home / myuser / watchDir / myapp中有一个rails应用程序,并且有一个incron作业设置来监视../watchDir进行修改。 Once triggered, incron will run a script, /usr/local/bin/myscript.sh. 触发后,incron将运行脚本/usr/local/bin/myscript.sh。 This is the only place I could get incron to run a script from. 这是我可以让incron从中运行脚本的唯一地方。 In that script I have calls to run rake
and bundle
commands in my root app. 在该脚本中,我有调用以在根应用程序中运行rake
和bundle
命令。 I The script IS being run (I have a test for that) but the bundle
and rake
commands both fail silently. I脚本正在运行(对此有一个测试),但是bundle
和rake
命令都无提示地失败。 I am fairly new to linux and internet research has given some solutions. 我对Linux相当陌生,并且互联网研究提供了一些解决方案。 I have all absolute paths in my scripts. 我的脚本中有所有绝对路径。 I tried adding my bash_profile to the scripts/incron commands. 我尝试将bash_profile添加到scripts / incron命令。 I tried having the incron script run another script located in my home directory. 我尝试让incron脚本运行位于我的主目录中的另一个脚本。 All the scripts are executable. 所有脚本都是可执行的。 I tried using the --gemfile
option for bundle
but that doesn't wokr. 我尝试对bundle
使用--gemfile
选项,但这不起作用。 Does anyone know what I have to do here? 有人知道我在这里做什么吗? Basically, I want to run the bundle
and rake
commands outside of RAILS_ROOT. 基本上,我想在RAILS_ROOT之外运行bundle
和rake
命令。 I also would like to know if incron complicates the use of the rails commands. 我还想知道incron是否会使rails命令的使用复杂化。 Thanks. 谢谢。
EDIT: 编辑:
Here are the relevant files: 以下是相关文件:
Incrontab: Incrontab:
/home/myuser/watchDir/ IN_MODIFY,IN_CLOSE_WRITE,IN_CLOSE_NOWRITE /bin/bash /usr/local/bin/runT.sh $@/$#
I also tried this: 我也试过这个:
/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' $@/$#
And here's the script it's calling: 这是它正在调用的脚本:
#!/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
My .bash_profile file: 我的.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
To sum up my last comments ... change your icrontab
entry to be: 总结一下我的最后评论...将您的icrontab
条目更改为:
/home/myuser/watchDir/ IN_MODIFY,IN_CLOSE_WRITE,IN_CLOSE_NOWRITE /bin/bash /usr/local/bin/runT.sh $@/$#
And the script to be: 脚本为:
#!/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.