I have a rails application in /home/myuser/watchDir/myapp and an incron job set to watch the ../watchDir for modification. Once triggered, incron will run a script, /usr/local/bin/myscript.sh. This is the only place I could get incron to run a script from. In that script I have calls to run rake
and bundle
commands in my root app. I The script IS being run (I have a test for that) but the bundle
and rake
commands both fail silently. I am fairly new to linux and internet research has given some solutions. I have all absolute paths in my scripts. I tried adding my bash_profile to the scripts/incron commands. I tried having the incron script run another script located in my home directory. All the scripts are executable. I tried using the --gemfile
option for bundle
but that doesn't wokr. Does anyone know what I have to do here? Basically, I want to run the bundle
and rake
commands outside of RAILS_ROOT. I also would like to know if incron complicates the use of the rails commands. Thanks.
EDIT:
Here are the relevant files:
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
# 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:
/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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.