Permalink
Browse files

Can write a basic run script to disk

  • Loading branch information...
Michael Sofaer and Raphael Sofaer Michael Sofaer and Raphael Sofaer
Michael Sofaer and Raphael Sofaer authored and Michael Sofaer and Raphael Sofaer committed Nov 19, 2010
0 parents commit 7b0c2b854c6735b45ffb8a429702da316fed1e9e
Showing with 122 additions and 0 deletions.
  1. +2 −0 Gemfile
  2. +38 −0 Gemfile.lock
  3. +8 −0 README.md
  4. +39 −0 lib/hellspawn.rb
  5. +30 −0 test/hellspawn_test.rb
  6. +5 −0 test/test_helper.rb
@@ -0,0 +1,2 @@
+source :gemcutter
+gem "wrong"
@@ -0,0 +1,38 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ ParseTree (3.0.6)
+ RubyInline (>= 3.7.0)
+ sexp_processor (>= 3.0.0)
+ RubyInline (3.8.6)
+ ZenTest (~> 4.3)
+ ZenTest (4.4.0)
+ diff-lcs (1.1.2)
+ file-tail (1.0.5)
+ spruz (>= 0.1.0)
+ predicated (0.2.2)
+ ruby2ruby (1.2.5)
+ ruby_parser (~> 2.0)
+ sexp_processor (~> 3.0)
+ ruby_parser (2.0.5)
+ sexp_processor (~> 3.0)
+ sexp_processor (3.0.5)
+ sourcify (0.4.0)
+ ruby2ruby (>= 1.2.5)
+ sexp_processor (>= 3.0.5)
+ spruz (0.2.2)
+ wrong (0.4.5)
+ ParseTree (~> 3.0)
+ diff-lcs (~> 1.1.2)
+ file-tail (~> 1.0)
+ predicated (>= 0.2.2)
+ ruby2ruby (~> 1.2)
+ ruby_parser (~> 2.0.4)
+ sexp_processor (~> 3.0)
+ sourcify (>= 0.3.0)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ wrong
@@ -0,0 +1,8 @@
+*Hellspawn* is for spawning. It spawns processes using daemontools.
+It makes sure that you are running the processes you claim you want to be running.
+
+ legion = Hellspawn.legion :base => "/directory/for/services"
+ legion.summon :name => "daemon_name", :executable => "daemon executable path"
+ legion.march!
+
+Now you have daemons.
@@ -0,0 +1,39 @@
+class Hellspawn
+ def self.legion(options)
+ Legion.new(options)
+ end
+ class Legion < Array
+ def initialize(options)
+ @options = options
+ end
+ def march!
+ #slaughter_stragglers!
+ each {|daemon| daemon.march!(@options[:base])}
+ end
+
+ def summon(options)
+ self << Daemon.new(options)
+ end
+ class Daemon < Hash
+ def initialize(options)
+ replace options
+ end
+ def name
+ self[:name]
+ end
+ def march!(base)
+ FileUtils.mkdir_p File.join(base, name)
+ run_file = File.open(File.join(base, name, "run"), "w+")
+ run_file.puts run_prep
+ run_file.puts run_script
+ run_file.close
+ end
+ def run_script
+ "exec #{self[:executable]}"
+ end
+ def run_prep
+ "exec 2&>1"
+ end
+ end
+ end
+end
@@ -0,0 +1,30 @@
+require 'test/test_helper'
+require 'lib/hellspawn'
+
+class BasicTest < Test::Unit::TestCase
+ def setup
+ @thin = {:name => "thin",
+ :executable => "/usr/local/bin/thin",
+ }
+ @legion = Hellspawn.legion(:base => "/tmp/test_services", :name => "test_legion")
+ end
+ def test_legion
+ assert {@legion.size == 0}
+ end
+ def test_summon
+ @legion.summon @thin
+ assert {@legion.first.name == "thin"}
+ end
+ def test_march
+ @legion.summon @thin
+ @legion.march!
+ run_script = File.read("/tmp/test_services/thin/run")
+ assert { run_script.match /exec \/usr\/local\/bin\/thin/ }
+ end
+ def test_stderr
+ @legion.summon @thin
+ @legion.march!
+ run_script = File.read("/tmp/test_services/thin/run")
+ assert { run_script.split("\n").first == "exec 2&>1" }
+ end
+end
@@ -0,0 +1,5 @@
+require 'rubygems'
+require 'test/unit'
+require 'wrong'
+require 'wrong/adapters/test_unit'
+Wrong.config[:color] = true

0 comments on commit 7b0c2b8

Please sign in to comment.