upstart-exporter 0.0.6 → 0.1.0

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/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Gemfile CHANGED
@@ -2,3 +2,12 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in upstart-exporter.gemspec
4
4
  gemspec
5
+
6
+ gem 'rake'
7
+ gem 'yard'
8
+ gem 'redcarpet'
9
+
10
+ group :test do
11
+ gem 'rspec'
12
+ gem 'fakefs', :require => 'fakefs/safe'
13
+ end
data/README.md CHANGED
@@ -8,7 +8,7 @@ It is often neccessary to run some supporting background tasks for rails project
8
8
 
9
9
  This gem is an attempt to provide a safe way for installing backround jobs, so that they run under some fixed user without root priveleges.
10
10
 
11
- The only interface to the gem is the script(*upstart-export*) it provides.
11
+ The only interface to the gem that should be used is the script(*upstart-export*) it provides.
12
12
 
13
13
  Installing
14
14
  ----------
@@ -72,9 +72,7 @@ where _myapp_ is the application name. This name only affects the names of gener
72
72
 
73
73
  in /etc/init/:
74
74
 
75
- fb-myapp-my_another_tail_cmd-real.conf
76
75
  fb-myapp-my_another_tail_cmd.conf
77
- fb-myapp-my_tail_cmd-real.conf
78
76
  fb-myapp-my_tail_cmd.conf
79
77
  fb-myapp.conf
80
78
 
data/bin/upstart-export CHANGED
@@ -33,6 +33,6 @@ begin
33
33
  else
34
34
  Upstart::Exporter.new(options).export
35
35
  end
36
- rescue Upstart::ExportError => e
36
+ rescue Upstart::Exporter::Error => e
37
37
  abort(e.to_s)
38
38
  end
@@ -0,0 +1,11 @@
1
+ class Upstart::Exporter::Error < RuntimeError
2
+ end
3
+
4
+ module Upstart::Exporter::Errors
5
+ def error(msg)
6
+ raise Upstart::Exporter::Error, msg
7
+ end
8
+ end
9
+
10
+
11
+
@@ -0,0 +1,43 @@
1
+ module Upstart::Exporter::Options
2
+ class CommandLine < Hash
3
+ include Upstart::Exporter::Errors
4
+
5
+ def initialize(command_line_args)
6
+ super
7
+ self[:commands] = if command_line_args[:clear]
8
+ {}
9
+ else
10
+ process_procfile(command_line_args[:procfile])
11
+ end
12
+ self[:app_name] = process_appname(command_line_args[:app_name])
13
+ end
14
+
15
+ def process_procfile(name)
16
+ error "#{name} is not a readable file" unless FileTest.file?(name)
17
+ commands = {}
18
+ content = File.read(name)
19
+ content.lines.each do |line|
20
+ line.chomp!
21
+ if line =~ /^(\w+?):(.*)$/
22
+ label = $1
23
+ command = $2
24
+ commands[label] = command
25
+ elsif line =~ /^\s*#/
26
+ # do nothing, comment
27
+ elsif line =~ /^\s*$/
28
+ # do nothing, empty
29
+ else
30
+ error "procfile lines should have the following format: 'some_label: command'"
31
+ end
32
+ end
33
+ commands
34
+ end
35
+
36
+ def process_appname(app_name)
37
+ error "Application name should contain only letters (and underscore) and be nonempty, so #{app_name.inspect} is not suitable" unless app_name =~ /^\w+$/
38
+ app_name
39
+ end
40
+
41
+ end
42
+ end
43
+
@@ -0,0 +1,35 @@
1
+ module Upstart::Exporter::Options
2
+ class Global < Hash
3
+ include Upstart::Exporter::Errors
4
+
5
+ DEFAULTS = {
6
+ 'helper_dir' => '/var/local/upstart_helpers/',
7
+ 'upstart_dir' => '/etc/init/',
8
+ 'run_user' => 'service',
9
+ 'prefix' => 'fb-'
10
+ }
11
+
12
+ CONF = '/etc/upstart-exporter.yaml'
13
+
14
+ def initialize
15
+ super
16
+ config = if FileTest.file?(CONF)
17
+ YAML::load(File.read(CONF))
18
+ else
19
+ $stderr.puts "#{CONF} not found"
20
+ {}
21
+ end
22
+ error "#{CONF} is not a valid YAML config" unless config.is_a?(Hash)
23
+ %w{helper_dir upstart_dir run_user prefix}.each do |param|
24
+ value = if config[param]
25
+ config[param]
26
+ else
27
+ $stderr.puts "Param #{param} is not set, taking default value #{DEFAULTS[param]}"
28
+ DEFAULTS[param]
29
+ end
30
+ self[param.to_sym] = value
31
+ end
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,58 @@
1
+ module Upstart
2
+ class Exporter
3
+ class Templates
4
+
5
+ def self.helper(binds)
6
+ interpolate(HELPER_TPL, binds)
7
+ end
8
+
9
+ def self.app(binds)
10
+ interpolate(APP_TPL, binds)
11
+ end
12
+
13
+ def self.command(binds)
14
+ interpolate(COMMAND_TPL, binds)
15
+ end
16
+
17
+ protected
18
+
19
+ HELPER_TPL = <<-HEREDOC
20
+ #!/bin/sh
21
+ {{cmd}}
22
+ HEREDOC
23
+
24
+ APP_TPL = <<-HEREDOC
25
+ pre-start script
26
+
27
+ bash << "EOF"
28
+ mkdir -p /var/log/{{app_name}}
29
+ chown -R {{run_user}} /var/log/{{app_name}}
30
+ EOF
31
+
32
+ end script
33
+ HEREDOC
34
+
35
+ COMMAND_TPL = <<-HEREDOC
36
+ start on starting {{app_name}}
37
+ stop on stopping {{app_name}}
38
+ respawn
39
+
40
+ script
41
+ touch /var/log/{{app_name}}/{{cmd_name}}.log
42
+ chown {{run_user}} /var/log/{{app_name}}/{{cmd_name}}.log
43
+ exec sudo -u {{run_user}} /bin/sh {{helper_cmd_conf}} >> /var/log/{{app_name}}/{{cmd_name}}.log 2>&1
44
+ end
45
+ HEREDOC
46
+
47
+ def self.interpolate(str, substitutes)
48
+ str_copy = str.dup
49
+ substitutes.each do |k, v|
50
+ str_copy.gsub!("{{#{k}}}", v)
51
+ end
52
+ str_copy
53
+ end
54
+
55
+ end
56
+ end
57
+ end
58
+
@@ -1,5 +1,5 @@
1
1
  module Upstart
2
2
  class Exporter
3
- VERSION = "0.0.6"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -1,179 +1,97 @@
1
1
  require "upstart-exporter/version"
2
+ require "upstart-exporter/templates"
3
+ require "upstart-exporter/errors"
4
+ require "upstart-exporter/options/global"
5
+ require "upstart-exporter/options/command_line"
2
6
 
3
7
  module Upstart
4
- class ExportError < RuntimeError; end
5
-
6
8
  class Exporter
7
- DEFAULTS = {
8
- 'helper_dir' => '/var/local/upstart_helpers/',
9
- 'upstart_dir' => '/etc/init/',
10
- 'run_user' => 'service'
11
- }
12
- CONF = '/etc/upstart-exporter.yaml'
13
-
14
- attr_accessor :helper_dir, :upstart_dir, :run_user
9
+ include Errors
15
10
 
16
- def initialize(options)
17
- process_opts(options)
18
- read_global_opts
19
- check_dir(@helper_dir)
20
- check_dir(@upstart_dir)
11
+ attr_reader :options
12
+
13
+ def initialize(command_line_args)
14
+ global_options = Options::Global.new
15
+ command_line_options = Options::CommandLine.new(command_line_args)
16
+ @options = global_options.merge(command_line_options)
17
+ ensure_dirs
21
18
  end
22
19
 
23
-
24
- def read_global_opts
25
- config = if FileTest.file?(CONF)
26
- YAML::load(File.read(CONF))
27
- else
28
- STDERR.puts "#{CONF} not found"
29
- {}
30
- end
31
- %w{helper_dir upstart_dir run_user}.each do |param|
32
- value = if config[param]
33
- config[param]
34
- else
35
- STDERR.puts "Param #{param} is not set, taking default value #{DEFAULTS[param]}"
36
- DEFAULTS[param]
37
- end
38
- self.send "#{param}=", value
20
+ def export
21
+ clear
22
+ export_app
23
+ options[:commands].each do |cmd_name, cmd|
24
+ export_command(cmd_name, cmd)
39
25
  end
40
26
  end
41
27
 
42
- def process_opts(options)
43
- @commands = if options[:clear]
44
- {}
45
- else
46
- process_procfile(options[:procfile])
28
+ def clear
29
+ FileUtils.rm(upstart_conf) if FileTest.file?(upstart_conf)
30
+ Dir[upstart_cmd_conf('*')].each do |f|
31
+ FileUtils.rm(f)
47
32
  end
48
- process_appname(options[:app_name])
49
- end
50
-
51
- def process_procfile(name)
52
- error "#{name} is not a readable file" unless FileTest.file?(name)
53
- commands = {}
54
- content = File.read(name)
55
- content.lines.each do |line|
56
- line.chomp!
57
- if line =~ /^(\w+?):(.*)$/
58
- label = $1
59
- command = $2
60
- commands[label] = command
61
- elsif line =~ /^\s*$/
62
- # do nothing
63
- else
64
- error "procfile lines should have the following format: 'some_label: command'"
65
- end
33
+ Dir[helper_cmd_conf('*')].each do |f|
34
+ FileUtils.rm(f)
66
35
  end
67
- commands
68
36
  end
69
37
 
70
- def process_appname(app_name)
71
- error "Application name should contain only letters (and underscore) and be nonempty, so #{app_name.inspect} is not suitable" unless app_name =~ /^\w+$/
72
- @app_name = "fb-#{app_name}"
38
+ protected
39
+
40
+ def ensure_dirs
41
+ ensure_dir(options[:helper_dir])
42
+ ensure_dir(options[:upstart_dir])
73
43
  end
74
44
 
75
- def check_dir(dir)
76
- FileUtils.mkdir_p(dir) unless FileTest.directory?(dir)
77
- error "Path #{dir} does not exist" unless FileTest.directory?(dir)
45
+ def app_name
46
+ options[:prefix] + options[:app_name]
78
47
  end
79
48
 
80
- def export
81
- clear
82
- export_app
83
- @commands.each do |cmd_name, cmd|
84
- export_command(cmd_name, cmd)
49
+ def export_app
50
+ app_conf = Templates.app :app_name => app_name, :run_user => options[:run_user]
51
+ File.open(upstart_conf, 'w') do |f|
52
+ f.write(app_conf)
85
53
  end
86
54
  end
87
55
 
88
- HELPER_TPL = <<-HEREDOC
89
- #!/bin/sh
90
- %s
91
- HEREDOC
92
-
93
- APP_TPL = <<-HEREDOC
94
- pre-start script
95
-
96
- bash << "EOF"
97
- mkdir -p /var/log/%s
98
- chown -R %s /var/log/%s
99
- EOF
100
-
101
- end script
102
- HEREDOC
103
-
104
- COMMAND_TPL = <<-HEREDOC
105
- start on starting %s
106
- stop on stopping %s
107
- HEREDOC
108
-
109
-
110
- COMMAND_REAL_TPL = <<-HEREDOC
111
- start on starting %s
112
- stop on stopping %s
113
- respawn
114
-
115
- exec sudo -u %s /bin/sh %s >> /var/log/%s/%s.log 2>&1
116
- HEREDOC
56
+ def ensure_dir(dir)
57
+ FileUtils.mkdir_p(dir) unless FileTest.directory?(dir)
58
+ error "Path #{dir} does not exist" unless FileTest.directory?(dir)
59
+ end
117
60
 
118
61
  def upstart_conf
119
- File.join(@upstart_dir, "#{@app_name}.conf")
62
+ File.join(options[:upstart_dir], "#{app_name}.conf")
120
63
  end
121
64
 
122
65
  def app_cmd(cmd_name)
123
- "#{@app_name}-#{cmd_name}"
66
+ "#{app_name}-#{cmd_name}"
124
67
  end
125
68
 
126
69
  def upstart_cmd_conf(cmd_name)
127
- File.join(@upstart_dir, "#{app_cmd(cmd_name)}.conf")
70
+ File.join(options[:upstart_dir], "#{app_cmd(cmd_name)}.conf")
128
71
  end
129
72
 
130
73
  def helper_cmd_conf(cmd_name)
131
- File.join(@helper_dir, "#{app_cmd(cmd_name)}.sh")
132
- end
133
-
134
- def clear
135
- FileUtils.rm(upstart_conf) if FileTest.file?(upstart_conf)
136
- Dir[upstart_cmd_conf('*')].each do |f|
137
- FileUtils.rm(f)
138
- end
139
- Dir[helper_cmd_conf('*')].each do |f|
140
- FileUtils.rm(f)
141
- end
142
- end
143
-
144
- def export_app
145
- app_conf = APP_TPL % [@app_name, @run_user, @app_name]
146
- File.open(upstart_conf, 'w') do |f|
147
- f.write(app_conf)
148
- end
74
+ File.join(options[:helper_dir], "#{app_cmd(cmd_name)}.sh")
149
75
  end
150
76
 
151
77
  def export_cmd_helper(cmd_name, cmd)
152
- helper_script_cont = HELPER_TPL % [cmd]
78
+ helper_script_cont = Templates.helper :cmd => cmd
153
79
  File.open(helper_cmd_conf(cmd_name), 'w') do |f|
154
80
  f.write(helper_script_cont)
155
81
  end
156
82
  end
157
83
 
158
- def export_cmd_upstart_confs(cmd_name)
159
- cmd_upstart_conf_content = COMMAND_TPL % [@app_name, @app_name]
84
+ def export_cmd_upstart_conf(cmd_name)
85
+ cmd_upstart_conf_content = Templates.command :app_name => app_name, :run_user => options[:run_user], :cmd_name => cmd_name, :helper_cmd_conf => helper_cmd_conf(cmd_name)
160
86
  File.open(upstart_cmd_conf(cmd_name), 'w') do |f|
161
87
  f.write(cmd_upstart_conf_content)
162
88
  end
163
-
164
- cmd_upstart_conf_content_real = COMMAND_REAL_TPL % [app_cmd(cmd_name), app_cmd(cmd_name), @run_user, helper_cmd_conf(cmd_name), @app_name, cmd_name]
165
- File.open(upstart_cmd_conf(cmd_name + '-real'), 'w') do |f|
166
- f.write(cmd_upstart_conf_content_real)
167
- end
168
89
  end
169
90
 
170
91
  def export_command(cmd_name, cmd)
171
92
  export_cmd_helper(cmd_name, cmd)
172
- export_cmd_upstart_confs(cmd_name)
93
+ export_cmd_upstart_conf(cmd_name)
173
94
  end
174
95
 
175
- def error(msg)
176
- raise Upstart::ExportError, msg
177
- end
178
96
  end
179
97
  end
@@ -0,0 +1,24 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe Upstart::Exporter::Errors do
4
+ context "when included" do
5
+ it "should provide #error method" do
6
+ class Foo
7
+ include Upstart::Exporter::Errors
8
+ end
9
+
10
+ Foo.new.should respond_to(:error)
11
+ end
12
+ end
13
+
14
+ describe "#error" do
15
+ it "should raise a correct exception" do
16
+ class Foo
17
+ include Upstart::Exporter::Errors
18
+ end
19
+
20
+ lambda{ Foo.new.error("arrgh") }.should raise_exception(Upstart::Exporter::Error)
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,61 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe Upstart::Exporter::Options::CommandLine do
4
+ context "when correct options are given" do
5
+ it "should give access to options like a hash" do
6
+ make_procfile('Procfile', 'ls_cmd: ls')
7
+ described_class.new(:app_name => 'someappname', :procfile => 'Procfile').should respond_to('[]')
8
+ end
9
+
10
+ it "should parse procfile" do
11
+ make_procfile('Procfile', 'ls_cmd: ls')
12
+ options = described_class.new(:app_name => 'someappname', :procfile => 'Procfile')
13
+ options[:commands].should == {'ls_cmd' => ' ls'}
14
+ end
15
+
16
+ it "should skip empty and commented lines in a procfile" do
17
+ make_procfile('Procfile', "ls_cmd1: ls1\n\nls_cmd2: ls2\n # fooo baaar")
18
+ options = described_class.new(:app_name => 'someappname', :procfile => 'Procfile')
19
+ options[:commands].should == {'ls_cmd1' => ' ls1', 'ls_cmd2' => ' ls2'}
20
+ end
21
+
22
+ it "should store app_name" do
23
+ make_procfile('Procfile', "ls_cmd1: ls1\n\nls_cmd2: ls2\n # fooo baaar")
24
+ options = described_class.new(:app_name => 'someappname', :procfile => 'Procfile')
25
+ options[:app_name].should == 'someappname'
26
+ end
27
+
28
+ it "should not process procfile if :clear arg is present" do
29
+ make_procfile('Procfile', "bad procfile")
30
+ options = described_class.new(:app_name => 'someappname', :procfile => 'Procfile', :clear => true)
31
+ options[:app_name].should == 'someappname'
32
+ options[:commands].should == {}
33
+ end
34
+ end
35
+
36
+ context "when bad app_name is passed" do
37
+ it "should raise exception" do
38
+ make_procfile('Procfile', 'ls_cmd: ls')
39
+ lambda{ described_class.new(:app_name => 'some appname', :procfile => 'Procfile') }.should raise_exception
40
+ lambda{ described_class.new(:app_name => '-someappname', :procfile => 'Procfile') }.should raise_exception
41
+ lambda{ described_class.new(:procfile => 'Procfile') }.should raise_exception
42
+ end
43
+ end
44
+
45
+ context "when bad Procfile is passed" do
46
+ it "should raise exception" do
47
+ make_procfile('Procfile', 'ls cmd: ls')
48
+ lambda{ described_class.new(:app_name => 'someappname', :procfile => 'Procfile') }.should raise_exception
49
+
50
+ make_procfile('Procfile', '-lscmd: ls')
51
+ lambda{ described_class.new(:app_name => 'someappname', :procfile => 'Procfile') }.should raise_exception
52
+
53
+ lambda{ described_class.new(:app_name => 'someappname', :procfile => '::') }.should raise_exception
54
+
55
+ lambda{ described_class.new(:app_name => 'someappname') }.should raise_exception
56
+ end
57
+ end
58
+
59
+
60
+ end
61
+
@@ -0,0 +1,52 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe Upstart::Exporter::Options::Global do
4
+ let(:defaults){ Upstart::Exporter::Options::Global::DEFAULTS }
5
+ let(:conf){ Upstart::Exporter::Options::Global::CONF }
6
+
7
+
8
+ it "should give access to options like a hash" do
9
+ capture(:stderr) do
10
+ described_class.new.should respond_to('[]')
11
+ end
12
+ end
13
+
14
+ context "when no config present" do
15
+
16
+ it "should provide default options" do
17
+ capture(:stderr) do
18
+ options = described_class.new
19
+ defaults.each do |option, default_value|
20
+ options[option.to_sym].should == default_value
21
+ end
22
+ end
23
+ end
24
+
25
+ end
26
+
27
+ context "when invalid config is given" do
28
+ it "should raise exception" do
29
+ make_global_config('zxc')
30
+ lambda{described_class.new}.should raise_exception
31
+ make_global_config([123].to_yaml)
32
+ lambda{described_class.new}.should raise_exception
33
+ end
34
+ end
35
+
36
+ context "when a valid config is given" do
37
+ it "should override default values" do
38
+ capture(:stderr) do
39
+ make_global_config({'run_user' => 'wwwww'}.to_yaml)
40
+ described_class.new[:run_user].should == 'wwwww'
41
+ end
42
+ end
43
+
44
+ it "should preserve default values for options not specified in the config" do
45
+ capture(:stderr) do
46
+ make_global_config({'run_user' => 'wwwww'}.to_yaml)
47
+ described_class.new[:prefix] == defaults['prefix']
48
+ end
49
+ end
50
+ end
51
+
52
+ end
@@ -0,0 +1,57 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe Upstart::Exporter::Templates do
4
+ describe ".app" do
5
+ it "should generate a valid app config" do
6
+
7
+ conf = <<-HEREDOC
8
+ pre-start script
9
+
10
+ bash << "EOF"
11
+ mkdir -p /var/log/SOMEAPP
12
+ chown -R SOMEUSER /var/log/SOMEAPP
13
+ EOF
14
+
15
+ end script
16
+ HEREDOC
17
+
18
+ described_class.app(:run_user => 'SOMEUSER', :app_name => 'SOMEAPP').should == conf
19
+ end
20
+ end
21
+
22
+ describe ".helper" do
23
+ it "should generate a valid helper script" do
24
+
25
+ conf = <<-HEREDOC
26
+ #!/bin/sh
27
+ SOME COMMAND
28
+ HEREDOC
29
+
30
+ described_class.helper(:cmd => 'SOME COMMAND').should == conf
31
+ end
32
+ end
33
+
34
+
35
+ describe ".helper" do
36
+ it "should generate a valid upstart script for a single command" do
37
+
38
+ conf = <<-HEREDOC
39
+ start on starting SOMEAPP
40
+ stop on stopping SOMEAPP
41
+ respawn
42
+
43
+ script
44
+ touch /var/log/SOMEAPP/SOMECMD.log
45
+ chown SOMEUSER /var/log/SOMEAPP/SOMECMD.log
46
+ exec sudo -u SOMEUSER /bin/sh HELPERPATH >> /var/log/SOMEAPP/SOMECMD.log 2>&1
47
+ end
48
+ HEREDOC
49
+
50
+ described_class.command(:run_user => 'SOMEUSER', :app_name => 'SOMEAPP', :cmd_name => 'SOMECMD', :helper_cmd_conf => 'HELPERPATH').should == conf
51
+ end
52
+ end
53
+
54
+
55
+
56
+ end
57
+
@@ -0,0 +1,63 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe Upstart::Exporter do
4
+ let(:tpl){ Upstart::Exporter::Templates }
5
+
6
+ let(:exporter) do
7
+ make_global_config({
8
+ 'helper_dir' => '/h',
9
+ 'upstart_dir' => '/u',
10
+ 'run_user' => 'u',
11
+ 'prefix' => 'p-'
12
+ }.to_yaml)
13
+ make_procfile('Procfile', 'ls_cmd: ls')
14
+ exporter = described_class.new({:app_name => 'app', :procfile => 'Procfile'})
15
+ end
16
+
17
+ describe '#export' do
18
+ it 'should make cleanup before export' do
19
+ exporter.should_receive(:clear)
20
+ exporter.export
21
+ end
22
+
23
+ it 'should create upstart scripts, folders and sh helpers' do
24
+ exporter.export
25
+ %w{/h/p-app-ls_cmd.sh /u/p-app.conf /u/p-app-ls_cmd.conf}.each do |f|
26
+ FileTest.file?(f).should be_true
27
+ end
28
+ end
29
+
30
+ it 'created scripts, folders and sh helpers should have valid content' do
31
+ exporter.export
32
+
33
+ File.read('/h/p-app-ls_cmd.sh').should == tpl.helper(:cmd => ' ls')
34
+ File.read('/u/p-app.conf').should == tpl.app(:run_user => 'u', :app_name => 'p-app')
35
+ File.read('/u/p-app-ls_cmd.conf').should == tpl.command(:run_user => 'u', :app_name => 'p-app', :cmd_name => 'ls_cmd', :helper_cmd_conf => '/h/p-app-ls_cmd.sh')
36
+ end
37
+ end
38
+
39
+ describe '#clear' do
40
+ it 'should remove exported app helpers an scripts' do
41
+ exporter.export
42
+ exporter.clear
43
+ Dir['/h/*'].should be_empty
44
+ Dir['/u/*'].should be_empty
45
+ end
46
+
47
+ it 'should keep files of other apps' do
48
+ exporter.export
49
+
50
+ make_procfile('Procfile1', 'ls_cmd: ls')
51
+ other_exporter = described_class.new({:app_name => 'other_app', :procfile => 'Procfile1'})
52
+ other_exporter.export
53
+
54
+ exporter.clear
55
+
56
+ %w{/h/p-other_app-ls_cmd.sh /u/p-other_app.conf /u/p-other_app-ls_cmd.conf}.each do |f|
57
+ FileTest.file?(f).should be_true
58
+ end
59
+ end
60
+ end
61
+
62
+ end
63
+
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ Bundler.require(:default, :test, :development)
5
+
6
+ require 'fakefs/spec_helpers'
7
+
8
+ require 'upstart-exporter'
9
+
10
+ Dir['spec/support/**/*.rb'].each do |f|
11
+ require f
12
+ end
13
+
14
+ RSpec.configure do |config|
15
+ config.include FakeFS::SpecHelpers
16
+ end
@@ -0,0 +1,6 @@
1
+ def make_global_config(content)
2
+ path = Upstart::Exporter::Options::Global::CONF
3
+ dir = File.dirname(path)
4
+ FileUtils.mkdir_p(dir)
5
+ File.open(path, 'w'){|f| f.write(content) }
6
+ end
@@ -0,0 +1,5 @@
1
+ def make_procfile(fname, content)
2
+ File.open(fname, 'w') do |f|
3
+ f.write content
4
+ end
5
+ end
@@ -0,0 +1,15 @@
1
+ require 'stringio'
2
+
3
+ def capture(*streams)
4
+ streams.map! { |stream| stream.to_s }
5
+ begin
6
+ result = StringIO.new
7
+ streams.each { |stream| eval "$#{stream} = result" }
8
+ yield
9
+ ensure
10
+ streams.each { |stream| eval("$#{stream} = #{stream.upcase}") }
11
+ end
12
+ result.string
13
+ end
14
+
15
+
@@ -16,8 +16,4 @@ Gem::Specification.new do |s|
16
16
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
17
  s.require_paths = ["lib"]
18
18
 
19
- s.add_development_dependency("rake")
20
- s.add_development_dependency("rspec")
21
- s.add_development_dependency("yard")
22
- s.add_development_dependency("redcarpet")
23
19
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: upstart-exporter
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 6
10
- version: 0.0.6
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ilya Averyanov
@@ -15,64 +15,9 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-12-15 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- version_requirements: &id001 !ruby/object:Gem::Requirement
22
- none: false
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- hash: 3
27
- segments:
28
- - 0
29
- version: "0"
30
- requirement: *id001
31
- type: :development
32
- prerelease: false
33
- name: rake
34
- - !ruby/object:Gem::Dependency
35
- version_requirements: &id002 !ruby/object:Gem::Requirement
36
- none: false
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- hash: 3
41
- segments:
42
- - 0
43
- version: "0"
44
- requirement: *id002
45
- type: :development
46
- prerelease: false
47
- name: rspec
48
- - !ruby/object:Gem::Dependency
49
- version_requirements: &id003 !ruby/object:Gem::Requirement
50
- none: false
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- hash: 3
55
- segments:
56
- - 0
57
- version: "0"
58
- requirement: *id003
59
- type: :development
60
- prerelease: false
61
- name: yard
62
- - !ruby/object:Gem::Dependency
63
- version_requirements: &id004 !ruby/object:Gem::Requirement
64
- none: false
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- hash: 3
69
- segments:
70
- - 0
71
- version: "0"
72
- requirement: *id004
73
- type: :development
74
- prerelease: false
75
- name: redcarpet
18
+ date: 2011-12-22 00:00:00 Z
19
+ dependencies: []
20
+
76
21
  description: Gem for converting Procfile-like files to upstart scripts
77
22
  email:
78
23
  - ilya@averyanov.org
@@ -85,6 +30,7 @@ extra_rdoc_files: []
85
30
  files:
86
31
  - .gitignore
87
32
  - .rbenv-version
33
+ - .rspec
88
34
  - .yardoc/checksums
89
35
  - .yardoc/objects/root.dat
90
36
  - .yardoc/proxy_types
@@ -110,7 +56,20 @@ files:
110
56
  - doc/method_list.html
111
57
  - doc/top-level-namespace.html
112
58
  - lib/upstart-exporter.rb
59
+ - lib/upstart-exporter/errors.rb
60
+ - lib/upstart-exporter/options/command_line.rb
61
+ - lib/upstart-exporter/options/global.rb
62
+ - lib/upstart-exporter/templates.rb
113
63
  - lib/upstart-exporter/version.rb
64
+ - spec/lib/upstart-exporter/errors_spec.rb
65
+ - spec/lib/upstart-exporter/options/command_line_spec.rb
66
+ - spec/lib/upstart-exporter/options/global_spec.rb
67
+ - spec/lib/upstart-exporter/templates_spec.rb
68
+ - spec/lib/upstart-exporter_spec.rb
69
+ - spec/spec_helper.rb
70
+ - spec/support/global_config.rb
71
+ - spec/support/procfile.rb
72
+ - spec/support/streams.rb
114
73
  - upstart-exporter.gemspec
115
74
  homepage: ""
116
75
  licenses: []
@@ -145,6 +104,14 @@ rubygems_version: 1.8.10
145
104
  signing_key:
146
105
  specification_version: 3
147
106
  summary: Gem for converting Procfile-like files to upstart scripts
148
- test_files: []
149
-
107
+ test_files:
108
+ - spec/lib/upstart-exporter/errors_spec.rb
109
+ - spec/lib/upstart-exporter/options/command_line_spec.rb
110
+ - spec/lib/upstart-exporter/options/global_spec.rb
111
+ - spec/lib/upstart-exporter/templates_spec.rb
112
+ - spec/lib/upstart-exporter_spec.rb
113
+ - spec/spec_helper.rb
114
+ - spec/support/global_config.rb
115
+ - spec/support/procfile.rb
116
+ - spec/support/streams.rb
150
117
  has_rdoc: