如何运行bash脚本从其目录外部更新Rails应用程序?

时间:2018-01-30 20:23:44

标签: ruby-on-rails bash rake

我有一个应该从/~目录运行的脚本:

#!/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)中。我做错了什么?

3 个答案:

答案 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
相关问题