[英]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.