Added basic support for Bluepill

This commit is contained in:
Hunter Nield
2011-08-22 21:24:34 +10:00
parent 6ad344d214
commit 21a041527c
4 changed files with 133 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
Bluepill.application("<%= app %>", :foreground => false) do |app|
app.uid = "<%= user %>"
app.gid = "<%= user %>"
<% engine.processes.values.each do |process| %>
<% 1.upto(concurrency[process.name]) do |num| %>
<% port = engine.port_for(process, num, options[:port]) %>
app.process("<%= process.name %>-<%=num%>") do |process|
process.start_command = "<%= process.command %>"
process.working_dir = "<%= engine.directory %>"
process.pid_file = "/var/run/<%= app %>-<%= process.name %>-<%=num%>.pid"
process.daemonize = true
process.environment = {"PORT" => "<%= port %>"}
process.stdout = process.stderr = "<%= log_root %>/<%= app %>-<%= process.name %>-<%=num%>.log"
process.monitor_children do |children|
children.stop_command "kill -QUIT {{PID}}"
end
end
<% end %>
<% end %>
end

View File

@@ -0,0 +1,29 @@
require "erb"
require "foreman/export"
class Foreman::Export::Bluepill < Foreman::Export::Base
def export(location, options={})
error("Must specify a location") unless location
FileUtils.mkdir_p location
app = options[:app] || File.basename(engine.directory)
user = options[:user] || app
log_root = options[:log] || "/var/log/#{app}"
template_root = options[:template]
Dir["#{location}/#{app}.pill"].each do |file|
say "cleaning up: #{file}"
FileUtils.rm(file)
end
concurrency = Foreman::Utils.parse_concurrency(options[:concurrency])
master_template = export_template("bluepill", "master.pill.erb", template_root)
master_config = ERB.new(master_template).result(binding)
write_file "#{location}/#{app}.pill", master_config
end
end

View File

@@ -0,0 +1,20 @@
require "spec_helper"
require "foreman/engine"
require "foreman/export/bluepill"
require "tmpdir"
describe Foreman::Export::Bluepill do
let(:procfile) { FileUtils.mkdir_p("/tmp/app"); write_procfile("/tmp/app/Procfile") }
let(:engine) { Foreman::Engine.new(procfile) }
let(:bluepill) { Foreman::Export::Bluepill.new(engine) }
before(:each) { load_export_templates_into_fakefs("bluepill") }
before(:each) { stub(bluepill).say }
it "exports to the filesystem" do
bluepill.export("/tmp/init")
File.read("/tmp/init/app.pill").should == example_export_file("bluepill/app.pill")
end
end

View File

@@ -0,0 +1,59 @@
Bluepill.application("app", :foreground => false) do |app|
app.uid = "app"
app.gid = "app"
app.process("alpha-1") do |process|
process.start_command = "./alpha"
process.working_dir = "/tmp/app"
process.pid_file = "/var/run/app-alpha-1.pid"
process.daemonize = true
process.environment = {"PORT" => "5000"}
process.stdout = process.stderr = "/var/log/app/app-alpha-1.log"
process.monitor_children do |children|
children.stop_command "kill -QUIT {{PID}}"
end
end
app.process("alpha-2") do |process|
process.start_command = "./alpha"
process.working_dir = "/tmp/app"
process.pid_file = "/var/run/app-alpha-2.pid"
process.daemonize = true
process.environment = {"PORT" => "5001"}
process.stdout = process.stderr = "/var/log/app/app-alpha-2.log"
process.monitor_children do |children|
children.stop_command "kill -QUIT {{PID}}"
end
end
app.process("bravo-1") do |process|
process.start_command = "./bravo"
process.working_dir = "/tmp/app"
process.pid_file = "/var/run/app-bravo-1.pid"
process.daemonize = true
process.environment = {"PORT" => "5100"}
process.stdout = process.stderr = "/var/log/app/app-bravo-1.log"
process.monitor_children do |children|
children.stop_command "kill -QUIT {{PID}}"
end
end
end