简体   繁体   English

我们如何通过另一个应用程序(都运行在同一台服务器上)运行一个应用程序的 rake 任务?

[英]How can we run a rake task of one application through another application (both running on the same server)?

Issue : I have two applications A & B both running on the same server.问题:我有两个应用程序 A 和 B,它们都在同一台服务器上运行。 I have a script in the filesystem我在文件系统中有一个脚本

cd /data/B/
bundle exec rake -T 

When i run the script through the rails console of application A it errors as the console loads the gems of A and the rake task fails当我通过应用程序 A 的 rails 控制台运行脚本时,它会出错,因为控制台加载了 A 的 gems 并且 rake 任务失败

  eg: system("sh ~/test.sh")

rake aborted!
LoadError: cannot load such file -- log4r
/home/kumolus/api/config/application.rb:9:in `require'
/home/kumolus/api/config/application.rb:9:in `<top (required)>'
/home/kumolus/api/Rakefile:1:in `require'
/home/kumolus/api/Rakefile:1:in `<top (required)>'
(See full trace by running task with --trace)

When i run the script through the unix command line (irrespective of my pwd) it works当我通过 unix 命令行(不管我的密码)运行脚本时,它可以工作

cd ~
sh test.sh  #works

cd /data/A   #my application A's dir
sh ~/test.sh   #also works

I need it to work through rails.Any help ?我需要它来通过 rails.Any 帮助? Thanks!谢谢!

Thanks guys for your help, I found a solution its due to bundler default behaviour.感谢大家的帮助,由于打包器的默认行为,我找到了一个解决方案。

I used with_clean_env method with a block and it gets executed.我将 with_clean_env 方法与一个块一起使用,它被执行了。

Thanks Team Cheers感谢团队干杯

I think cd'ing to the folder should be sufficient to switch the environment within the shell process which is doing the cd'ing .我认为 cd'ing 到文件夹应该足以在执行 cd'ing 的 shell 进程中切换环境。 Try this.尝试这个。

Go into project B and do进入项目B并做

which bundle

in the command line, and copy the result somewhere.在命令行中,并将结果复制到某处。 Then do然后做

which rake

and copy the result of that.并复制结果。

Then, switch to project A and start a rails console.然后,切换到项目 A 并启动一个 rails 控制台。 Then try this:然后试试这个:

`cd /path/to/projectB; bundle exec rake  -T`

If that doesn't work, try this:如果这不起作用,请尝试以下操作:

`cd /path/to/projectB; <result of doing "which bundle" earlier> exec rake -T`

Then if it still doesn't work, try this:然后,如果它仍然不起作用,请尝试以下操作:

`cd /path/to/projectB; <result of doing "which bundle" earlier> exec <result of doing "which rake" earlier> -T`

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM