Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #59 from hunter/bluepill

Bluepill export
  • Loading branch information...
commit b25dfee62d420a2166789b6eb6d4a90b9de9b0bf 2 parents 4355875 + 9db97ab
@ddollar ddollar authored
View
27 data/export/bluepill/master.pill.erb
@@ -0,0 +1,27 @@
+Bluepill.application("<%= app %>", :foreground => false, :log_file => "/var/log/bluepill.log") 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.gsub("$PORT", port.to_s) %>"
+
+ process.working_dir = "<%= engine.directory %>"
+ process.daemonize = true
+ process.environment = {"PORT" => "<%= port %>"}
+ process.stop_signals = [:quit, 30.seconds, :term, 5.seconds, :kill]
+
+ process.stdout = process.stderr = "<%= log_root %>/<%= app %>-<%= process.name %>-<%=num%>.log"
+
+ process.monitor_children do |children|
+ children.stop_command "kill -QUIT {{PID}}"
+ end
+
+ process.group = "<%= app %>-<%= process.name %>"
+ end
+<% end %>
+<% end %>
+end
View
1  lib/foreman/cli.rb
@@ -40,6 +40,7 @@ def export(format, location=nil)
formatter = case format
when "inittab" then Foreman::Export::Inittab
when "upstart" then Foreman::Export::Upstart
+ when "bluepill" then Foreman::Export::Bluepill
else error "Unknown export format: #{format}."
end
View
1  lib/foreman/export.rb
@@ -7,3 +7,4 @@ class Exception < ::Exception; end
require "foreman/export/base"
require "foreman/export/inittab"
require "foreman/export/upstart"
+require "foreman/export/bluepill"
View
29 lib/foreman/export/bluepill.rb
@@ -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
20 spec/foreman/export/bluepill_spec.rb
@@ -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
65 spec/resources/export/bluepill/app.pill
@@ -0,0 +1,65 @@
+Bluepill.application("app", :foreground => false, :log_file => "/var/log/bluepill.log") do |app|
+
+ app.uid = "app"
+ app.gid = "app"
+
+
+
+
+ app.process("alpha-1") do |process|
+ process.start_command = "./alpha"
+
+ process.working_dir = "/tmp/app"
+ process.daemonize = true
+ process.environment = {"PORT" => "5000"}
+ process.stop_signals = [:quit, 30.seconds, :term, 5.seconds, :kill]
+
+ process.stdout = process.stderr = "/var/log/app/app-alpha-1.log"
+
+ process.monitor_children do |children|
+ children.stop_command "kill -QUIT {{PID}}"
+ end
+
+ process.group = "app-alpha"
+ end
+
+
+ app.process("alpha-2") do |process|
+ process.start_command = "./alpha"
+
+ process.working_dir = "/tmp/app"
+ process.daemonize = true
+ process.environment = {"PORT" => "5001"}
+ process.stop_signals = [:quit, 30.seconds, :term, 5.seconds, :kill]
+
+ process.stdout = process.stderr = "/var/log/app/app-alpha-2.log"
+
+ process.monitor_children do |children|
+ children.stop_command "kill -QUIT {{PID}}"
+ end
+
+ process.group = "app-alpha"
+ end
+
+
+
+
+ app.process("bravo-1") do |process|
+ process.start_command = "./bravo"
+
+ process.working_dir = "/tmp/app"
+ process.daemonize = true
+ process.environment = {"PORT" => "5100"}
+ process.stop_signals = [:quit, 30.seconds, :term, 5.seconds, :kill]
+
+ process.stdout = process.stderr = "/var/log/app/app-bravo-1.log"
+
+ process.monitor_children do |children|
+ children.stop_command "kill -QUIT {{PID}}"
+ end
+
+ process.group = "app-bravo"
+ end
+
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.