Skip to content

Instantly share code, notes, and snippets.

@matsuda
Created June 2, 2009 05:28
Show Gist options
  • Save matsuda/122074 to your computer and use it in GitHub Desktop.
Save matsuda/122074 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# =======================================================
# 外部連携するRails開発において外部サーバのモックアプリとRailsアプリを同時起動するスクリプト
#
# ex.)
# RAILS_ROOT/lib/external_server/server.rb
#
# $ ruby script/external_server
# => Rails'command run 'script/server'
# オプションはRailsのものと同じ
#
# mongrel_railsを利用する場合
# $ ruby script/external_server mongrel_rails
# => 'mongrel_rails'
# =======================================================
RAILS_ROOT = File.expand_path( File.join( File.dirname(__FILE__), '..') ) unless defined? RAILS_ROOT
t1 = Thread.new do
if ARGV.first =~ /^mongrel_rails/
system "mongrel_rails start"
else
system "#{File.join(RAILS_ROOT, 'script', 'server')} #{ARGV.join(' ')}"
end
end
unless ARGV.first =~ /^-h/
t2 = Thread.new do
system 'ruby', "#{File.join(RAILS_ROOT, 'lib', 'external_server', 'server.rb')}"
end
t2.join
end
t1.join
if ARGV.first =~ /^-h/
Thread.kill(t1)
Thread.exit
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment