warehouse_supervisor 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +11 -0
- data/README.md +21 -9
- data/Rakefile +1 -0
- data/bin/warehouse_supervisor +1 -1
- data/example/processes.conf.erb +8 -0
- data/example/warehouse_supervisor.yml +4 -0
- data/lib/warehouse_supervisor.rb +1 -0
- data/lib/warehouse_supervisor/main.rb +46 -0
- data/lib/warehouse_supervisor/program_renderer.rb +1 -0
- data/lib/warehouse_supervisor/tasks.rb +22 -0
- data/lib/warehouse_supervisor/template_binding.rb +5 -1
- data/lib/warehouse_supervisor/version.rb +1 -1
- data/lib/warehouse_supervisor/warehouse_supervisor_cli.rb +4 -31
- data/spec/warehouse_supervisor/program_renderer_spec.rb +13 -2
- data/spec/warehouse_supervisor/renderer_spec.rb +0 -2
- data/spec/warehouse_supervisor/template_binding_spec.rb +0 -2
- data/warehouse_supervisor.gemspec +0 -1
- metadata +10 -21
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -18,25 +18,37 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
Warehouse Supervisor may be used either from its own CLI interface or from rake, both provide the same commands:
|
22
22
|
|
23
23
|
### print
|
24
24
|
|
25
25
|
warehouse_supervisor print -g production -c config.yml processes.conf.erb
|
26
|
+
|
27
|
+
or
|
28
|
+
|
29
|
+
rake warehouse_supervisor:print WS_GROUP=production CONFIG=config.yml TEMPLATES=processes.conf.erb
|
26
30
|
|
27
|
-
This will print
|
31
|
+
This will print the programs in config.yml, using the templates in processes.conf.erb.
|
32
|
+
|
33
|
+
Note that only [program:x] sections are printed. The result of this command is intended to be redirected to a file to be
|
34
|
+
[included in your main supervisord.conf file](http://supervisord.org/configuration.html#include-section-settings)
|
28
35
|
|
29
36
|
### start
|
30
37
|
|
31
38
|
warehouse_supervisor start -g production -c config.yml processes.conf.erb
|
32
39
|
|
40
|
+
or
|
41
|
+
|
42
|
+
rake warehouse_supervisor:start WS_GROUP=production CONFIG=config.yml TEMPLATES=processes.conf.erb
|
43
|
+
|
44
|
+
|
33
45
|
This will start a supervisor instance running in the foreground with the config you specified
|
34
46
|
|
35
47
|
Both these commands take the following options:
|
36
48
|
|
37
|
-
*
|
38
|
-
*
|
39
|
-
*
|
49
|
+
* `--group | -g`, `WS_GROUP=` Group to use.
|
50
|
+
* `--config | -c`, `CONFIG=` Definition file.
|
51
|
+
* ` `, `TEMPLATES=` Templates file.
|
40
52
|
|
41
53
|
## Files
|
42
54
|
|
@@ -50,10 +62,10 @@ Warehouse Supervisor needs 2 files to work:
|
|
50
62
|
This is an erb file where you'll define the different *program templates* that your app uses, for example:
|
51
63
|
|
52
64
|
<% template :resque_web do %>
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
65
|
+
user = <%= user || ENV["USER"] %>
|
66
|
+
directory = <%=dir || ENV["RAILS_ROOT"]%>
|
67
|
+
command = bundle exec resque-web -F -L -p 5678 config/resque_config.rb
|
68
|
+
environment = HOME='<%=home || ENV["HOME"]%>',USER=<%=user || ENV["USER"]%>
|
57
69
|
<% end %>
|
58
70
|
|
59
71
|
Each program template that you need will be define in a `template` block.
|
data/Rakefile
CHANGED
data/bin/warehouse_supervisor
CHANGED
data/example/processes.conf.erb
CHANGED
@@ -23,3 +23,11 @@
|
|
23
23
|
environment = HOME='<%=home || ENV["HOME"]%>',USER=<%=user || ENV["USER"]%>, RAILS_ENV=<%=rails_env || ENV["RAILS_ENV"]%>, VERBOSE=1
|
24
24
|
<% end %>
|
25
25
|
|
26
|
+
<% template :ls do %>
|
27
|
+
user = <%= user || ENV["USER"] %>
|
28
|
+
directory = <%=dir || ENV["HOME"]%>
|
29
|
+
command = ls
|
30
|
+
environment = HOME='<%=home || ENV["HOME"]%>',USER=<%=user || ENV["USER"]%>
|
31
|
+
redirect_stderr = true
|
32
|
+
<% end %>
|
33
|
+
|
data/lib/warehouse_supervisor.rb
CHANGED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'tempfile'
|
3
|
+
require 'warehouse_supervisor/renderer'
|
4
|
+
|
5
|
+
module WarehouseSupervisor
|
6
|
+
class Main
|
7
|
+
def initialize(erb_file, options={})
|
8
|
+
@erb_file = erb_file
|
9
|
+
@options = options
|
10
|
+
end
|
11
|
+
|
12
|
+
def generate_contents
|
13
|
+
unless File.exist?(@options[:config])
|
14
|
+
STDERR.puts "Bad file '#{@options[:config]}'"
|
15
|
+
exit 1
|
16
|
+
end
|
17
|
+
unless File.exist?(@erb_file)
|
18
|
+
STDERR.puts "Bad file '#{@erb_file}'"
|
19
|
+
exit 1
|
20
|
+
end
|
21
|
+
definitions = YAML.load(File.read(@options[:config]))[@options[:group].to_s]
|
22
|
+
unless definitions
|
23
|
+
STDERR.puts "Bad group '#{@options[:group]}'"
|
24
|
+
exit 1
|
25
|
+
end
|
26
|
+
erb_content = File.read(@erb_file)
|
27
|
+
Renderer.new(definitions, erb_content).render
|
28
|
+
end
|
29
|
+
|
30
|
+
def start
|
31
|
+
Tempfile.open("supervisord.conf") do |f|
|
32
|
+
Tempfile.open("supervisord.log") do |l|
|
33
|
+
f.puts "[supervisord]"
|
34
|
+
f.puts "nodaemon = true"
|
35
|
+
f.puts "logfile = #{l.path}"
|
36
|
+
f.puts "loglevel = debug"
|
37
|
+
f.write self.generate_contents
|
38
|
+
f.flush
|
39
|
+
command = "supervisord -c '#{f.path}'"
|
40
|
+
puts command
|
41
|
+
exec command
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -12,6 +12,7 @@ module WarehouseSupervisor
|
|
12
12
|
def render(program_name)
|
13
13
|
program_definition = TemplateBinding.new(program_name, @definitions[program_name])
|
14
14
|
ERB.new(@erb_content, nil, nil, "@output").result(program_definition.get_binding).gsub(/^$\n/, "").gsub(/^[\s]+/, "")
|
15
|
+
program_definition._output.gsub(/^$\n/, "").gsub(/^[\s]+/, "")
|
15
16
|
end
|
16
17
|
end
|
17
18
|
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'warehouse_supervisor'
|
2
|
+
|
3
|
+
namespace :warehouse_supervisor do
|
4
|
+
|
5
|
+
def get_opts
|
6
|
+
erb_file = ENV['TEMPLATES'] || raise("required TEMPLATES file")
|
7
|
+
config_file = ENV['CONFIG']|| raise("required CONFIG file")
|
8
|
+
group = ENV['WS_GROUP'] || raise("required configuration WS_GROUP")
|
9
|
+
[erb_file, {:group => group, :config => config_file}]
|
10
|
+
end
|
11
|
+
|
12
|
+
desc "output the file acording to the config"
|
13
|
+
task :print do
|
14
|
+
puts WarehouseSupervisor::Main.new(*get_opts()).generate_contents
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "start an undemonized supervisor with file"
|
18
|
+
task :start do
|
19
|
+
puts WarehouseSupervisor::Main.new(*get_opts()).start
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -1,6 +1,9 @@
|
|
1
1
|
module WarehouseSupervisor
|
2
2
|
|
3
3
|
class TemplateBinding
|
4
|
+
|
5
|
+
attr_reader :_output
|
6
|
+
|
4
7
|
def initialize(program_name, hash)
|
5
8
|
@program_name = program_name
|
6
9
|
@template = hash["template"]
|
@@ -12,8 +15,9 @@ module WarehouseSupervisor
|
|
12
15
|
|
13
16
|
def template(t)
|
14
17
|
if @template == t.to_s
|
15
|
-
@output
|
18
|
+
@output = "[program:#{@program_name}]"
|
16
19
|
yield
|
20
|
+
@_output = @output.dup
|
17
21
|
end
|
18
22
|
end
|
19
23
|
|
@@ -1,46 +1,19 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler/setup'
|
3
|
-
require 'yaml'
|
4
|
-
require 'tempfile'
|
5
|
-
require 'fileutils'
|
6
1
|
require 'thor'
|
7
|
-
require 'warehouse_supervisor
|
2
|
+
require 'warehouse_supervisor'
|
8
3
|
|
9
4
|
module WarehouseSupervisor
|
10
5
|
class WarehouseSupervisorCli < Thor
|
11
|
-
class_option :group, :aliases => :g, :
|
6
|
+
class_option :group, :aliases => :g, :required => true
|
12
7
|
class_option :config, :aliases => :c, :required => true
|
13
8
|
|
14
9
|
desc "print file", "output the file acording to the config"
|
15
10
|
def print(erb_file)
|
16
|
-
puts
|
11
|
+
puts WarehouseSupervisor::Main.new(erb_file, options).generate_contents
|
17
12
|
end
|
18
13
|
|
19
14
|
desc "start file", "start an undemonized supervisor with file"
|
20
|
-
option :log_dir, :aliases => :q, :default => "log"
|
21
15
|
def start(erb_file)
|
22
|
-
|
23
|
-
log_dir = options[:log_dir]
|
24
|
-
f.puts "[supervisord]"
|
25
|
-
f.puts "logfile = #{File.join(log_dir, "supervisord.log")}"
|
26
|
-
f.puts "childlogdir = #{log_dir}"
|
27
|
-
f.puts "nodaemon = true"
|
28
|
-
f.puts
|
29
|
-
f.write generate_contents(options[:group], options[:config], erb_file)
|
30
|
-
f.flush
|
31
|
-
FileUtils.mkdir_p options[:log_dir]
|
32
|
-
command = "supervisord -c '#{f.path}'"
|
33
|
-
puts command
|
34
|
-
exec command
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def generate_contents(group, definitions_file, erb_file)
|
41
|
-
definitions = YAML.load(File.read(definitions_file))[group.to_s]
|
42
|
-
erb_content = File.read(erb_file)
|
43
|
-
Renderer.new(definitions, erb_content).render
|
16
|
+
WarehouseSupervisor::Main.new(erb_file, options).start
|
44
17
|
end
|
45
18
|
|
46
19
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler/setup'
|
3
1
|
require 'yaml'
|
4
2
|
require 'warehouse_supervisor/program_renderer'
|
5
3
|
|
@@ -34,4 +32,17 @@ describe ProgramRenderer do
|
|
34
32
|
pr = ProgramRenderer.new(definitions["development"], erb_content).render("resque_web")
|
35
33
|
pr.should_not include "^\s+"
|
36
34
|
end
|
35
|
+
|
36
|
+
it "should not print stuff outside of the template" do
|
37
|
+
erb_content = %q{
|
38
|
+
I should not appear (upper)
|
39
|
+
|
40
|
+
<% template :tal do %>
|
41
|
+
awambabaluba
|
42
|
+
<% end %>
|
43
|
+
|
44
|
+
I should not appear (downer)
|
45
|
+
}
|
46
|
+
pr = ProgramRenderer.new({"cual" => {"template" => "tal"}}, erb_content).render("cual").should_not =~ /appear/
|
47
|
+
end
|
37
48
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: warehouse_supervisor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Diego Guerra
|
@@ -15,10 +15,10 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2013-04
|
18
|
+
date: 2013-05-04 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
|
-
name:
|
21
|
+
name: thor
|
22
22
|
prerelease: false
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
24
|
none: false
|
@@ -31,24 +31,10 @@ dependencies:
|
|
31
31
|
version: "0"
|
32
32
|
type: :runtime
|
33
33
|
version_requirements: *id001
|
34
|
-
- !ruby/object:Gem::Dependency
|
35
|
-
name: thor
|
36
|
-
prerelease: false
|
37
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
-
none: false
|
39
|
-
requirements:
|
40
|
-
- - ">="
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
hash: 3
|
43
|
-
segments:
|
44
|
-
- 0
|
45
|
-
version: "0"
|
46
|
-
type: :runtime
|
47
|
-
version_requirements: *id002
|
48
34
|
- !ruby/object:Gem::Dependency
|
49
35
|
name: rspec
|
50
36
|
prerelease: false
|
51
|
-
requirement: &
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
52
38
|
none: false
|
53
39
|
requirements:
|
54
40
|
- - ">="
|
@@ -58,7 +44,7 @@ dependencies:
|
|
58
44
|
- 0
|
59
45
|
version: "0"
|
60
46
|
type: :development
|
61
|
-
version_requirements: *
|
47
|
+
version_requirements: *id002
|
62
48
|
description: Easily create and run supervisord configuration files
|
63
49
|
email:
|
64
50
|
- diego.guerra.suarez@gmail.com
|
@@ -70,6 +56,7 @@ extra_rdoc_files: []
|
|
70
56
|
|
71
57
|
files:
|
72
58
|
- .gitignore
|
59
|
+
- CHANGELOG.md
|
73
60
|
- Gemfile
|
74
61
|
- LICENSE.txt
|
75
62
|
- README.md
|
@@ -78,8 +65,10 @@ files:
|
|
78
65
|
- example/processes.conf.erb
|
79
66
|
- example/warehouse_supervisor.yml
|
80
67
|
- lib/warehouse_supervisor.rb
|
68
|
+
- lib/warehouse_supervisor/main.rb
|
81
69
|
- lib/warehouse_supervisor/program_renderer.rb
|
82
70
|
- lib/warehouse_supervisor/renderer.rb
|
71
|
+
- lib/warehouse_supervisor/tasks.rb
|
83
72
|
- lib/warehouse_supervisor/template_binding.rb
|
84
73
|
- lib/warehouse_supervisor/version.rb
|
85
74
|
- lib/warehouse_supervisor/warehouse_supervisor_cli.rb
|