我有一个应该从/~
目录运行的脚本:
#!/bin/bash
APP=/root/apps/monitoring
cd $APP
git pull
rake assets:precompile RAILS_ENV=production
touch $APP/tmp/restart.txt
正如您所看到的,它会提取新提交并更新资产并重新启动Apache。问题是当它运行rake assets:precompile RAILS_ENV=production
行时,它说:
Could not find proper version of rake (12.1.0) in any of the sources
Run `bundle install` to install missing gems.
这很奇怪,因为我应该在执行此命令时位于应用程序的文件夹(/ root / apps / monitoring)中。我做错了什么?
答案 0 :(得分:1)
请尝试
#!/bin/bash
APP=/root/apps/monitoring
cd $APP
git pull
bundle exec rake assets:precompile RAILS_ENV=production
touch $APP/tmp/restart.txt
使用bundle exec
它应该有效。
答案 1 :(得分:1)
您可能需要在脚本(https://rvm.io/workflow/scripting)中加载rvm,并且可以选择适当的ruby / gemset。
另外,您可以考虑使用bundle
rvm wrapper
包装器
答案 2 :(得分:1)
我使用bash脚本包装器运行rake任务。诀窍是在任务启动后使用source命令加载rvm环境
example.sh
#!/bin/bash
# change the directory
cd /home/ubuntu/GSeries
# load rvm ruby
source /home/ubuntu/.rvm/environments/ruby-2.4.2@mygemset
bundle exec rake db:prune_logs RAILS_ENV="production" &>> /home/ubuntu/GSeries/log/prune_logs.log