Run a command in the context of a different app

Très

I have two rails apps on the same server, let's call them A and B.

I am trying to have app A restart app B via app B's own capistrano task. Unfortunately, even after cd-ing to app B's directory, it is trying to run app A's capistrano instead. Am I missing something?

example code

system("cd /apps/appB/current && pwd && bundle exec cap:restart")

pwd correctly returns the path of appB (/apps/appB/current), however, in there is a traceback for cap:restart. This is because it is still trying to run the cap command in the context of appA, e.g.

/apps/appA/shared/bundle/ruby/1.9.1/gems/capistrano-2.15.4/lib/capistrano/configuration/loading.rb:152:in 'require': cannot load such file -- airbrake/capistrano (LoadError) from /apps/appA/shared/bundle/ruby/1.9.1/gems/capistrano-2.15.4/lib/capistrano/configuration/loading.rb:152:in 'require'.

I tried without 'bundle exec', and have tried some other ways of making system calls. I also created a bash script in another directory and tried to run it that way.

All methods described exhibit the same behaviour.

Your help would be greatly appreciated =)

Tim Moore

You need to use Bundler.with_clean_env to ensure that your subprocess doesn't pick up your current Bundler environment:

Bundler.with_clean_env do
  system("cd /apps/appB/current && pwd && bundle exec cap:restart")
end

This is essentially the same problem as Install bundle of gem within other rails application

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How to run command as different user

분류에서Dev

How to have 2 different web/app servers for the same domain but different context path?

분류에서Dev

How do I run a gui app from the command line?

분류에서Dev

grep multiple patterns with different context

분류에서Dev

Order of Run command in JavaScript

분류에서Dev

Invoking a command in Run Window

분류에서Dev

Run an application with different TimeZone

분류에서Dev

Is sed run as a different user?

분류에서Dev

Run tasks in different threads

분류에서Dev

Run a command with the argument from the last command

분류에서Dev

run command in bash and then exit without killing the command

분류에서Dev

Java Fx TreeTableView different Context Menu items

분류에서Dev

How to run command on connect to network

분류에서Dev

Cannot run Android ADB command

분류에서Dev

How to run a command in background always?

분류에서Dev

Run a command with wildcards in each subdirectory

분류에서Dev

Run a command based on stdout frequency

분류에서Dev

How to know the command run by a process?

분류에서Dev

Cannot run any sudo command

분류에서Dev

Run command from history with parameters

분류에서Dev

Shell script to run Linux command on multiple servers command by command

분류에서Dev

Windows Store app - Grid app with different items

분류에서Dev

Shell script: run screen, open several screens and run a command in each

분류에서Dev

Is it possible to easily find the Command Prompt equivalent of a context menu item?

분류에서Dev

What does "Run command as a login shell" do?

분류에서Dev

Unable to run any apt-get command

분류에서Dev

How to run a command or script at screen lock/unlock?

분류에서Dev

dockerode pass args to run command _ Nodejs Docker

분류에서Dev

How to run a VirtualBox VM from command line?

Related 관련 기사

뜨겁다태그

보관