foreman-export-allah 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 25b411f33ed0f03af45c5792d83455a958257f3a
4
+ data.tar.gz: d60efe333d9e610f45dd8fe592f1463b93ea7fc3
5
+ SHA512:
6
+ metadata.gz: 235c50bad12d7c16a0b120bda86968bdaac47502e102b75a5063c7302f5ee61314cca376a961a15f761d3d0cfe54b2981ef628b8787f5994b1e64eac525574b4
7
+ data.tar.gz: 298c23490a1c5527b13c2e272a105b18b1ba455e5bf0e634d98d33cf43f46525a6be49e491a9762dfe147b5c0038c04aad3040dd6d47c5578ce73db8ab230c0a
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ /Gemfile.lock
2
+ /pkg
3
+ /tmp
4
+ /.yardoc
data/History.rdoc ADDED
@@ -0,0 +1,9 @@
1
+ == v0.1.0 [2013-01-01] Michael Granger <ged@FaerieMUD.org>
2
+
3
+ Updated for newer versions of Foreman.
4
+
5
+
6
+ == v0.0.1 [2012-04-27] Michael Granger <ged@FaerieMUD.org>
7
+
8
+ Initial release.
9
+
data/README.md ADDED
@@ -0,0 +1,66 @@
1
+ An exporter for David Dollar's [Foreman](https://github.com/ddollar/foreman)
2
+ that outputs service directories that can be managed by a per-user `svscan`,
3
+ with additional configuration which makes it
4
+ [allah](https://github.com/mpalmer/allah)-compatible.
5
+
6
+
7
+ # Prerequisites
8
+
9
+ * Ruby 2.0.0 or later
10
+ * Foreman
11
+
12
+
13
+ # Installation
14
+
15
+ $ gem install foreman-export-allah
16
+
17
+
18
+ # Usage
19
+
20
+ To export your Procfile to a `~/service` directory:
21
+
22
+ $ foreman export allah ~/service
23
+
24
+ This will create a `~/service/<app>-<proc>` directory for each `Procfile`
25
+ process. If you have the concurrency set to something > 1 for any of them it
26
+ will create an individual numbered service directory for each one in the
27
+ format: `~/service/<app>-<proc>-<num>`.
28
+
29
+ Each directory will be generated with a `down` file, which will prevent
30
+ supervise from automatically starting it before you have a chance to look it over.
31
+ After you confirm that everything looks okay, you can start them up just by
32
+ removing `down` on each service, or running `allah start <app>`.
33
+
34
+
35
+ # License
36
+
37
+ Copyright (c) 2012, Michael Granger
38
+ Copyright (c) 2015, Matt Palmer
39
+ All rights reserved.
40
+
41
+ Redistribution and use in source and binary forms, with or without
42
+ modification, are permitted provided that the following conditions are met:
43
+
44
+ * Redistributions of source code must retain the above copyright notice,
45
+ this list of conditions and the following disclaimer.
46
+
47
+ * Redistributions in binary form must reproduce the above copyright notice,
48
+ this list of conditions and the following disclaimer in the documentation
49
+ and/or other materials provided with the distribution.
50
+
51
+ * Neither the name of the author/s, nor the names of the project's
52
+ contributors may be used to endorse or promote products derived from this
53
+ software without specific prior written permission.
54
+
55
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
56
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
58
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
59
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
60
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
61
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
62
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
63
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
64
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
65
+
66
+
@@ -0,0 +1,8 @@
1
+ #!/bin/sh
2
+
3
+ <% if self.log %>
4
+ % logdir = Pathname(self.log) + '/' + procdir.basename
5
+ exec multilog t <%= logdir %>
6
+ <% else %>
7
+ exec multilog t ./main
8
+ <% end %>
@@ -0,0 +1,5 @@
1
+ #!/bin/sh
2
+
3
+ exec 2>&1
4
+ exec envdir ./env <%= process.command %>
5
+
@@ -0,0 +1,33 @@
1
+ require 'git-version-bump' rescue nil
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "foreman-export-allah"
5
+
6
+ s.version = GVB.version rescue "0.0.0.1.NOGVB"
7
+ s.date = GVB.date rescue Time.now.strftime("%Y-%m-%d")
8
+
9
+ s.platform = Gem::Platform::RUBY
10
+
11
+ s.summary = "Export a Foreman Procfile to allah services"
12
+
13
+ s.authors = ["Matt Palmer"]
14
+ s.email = ["theshed+foreman-export-allah@hezmatt.org"]
15
+ s.homepage = "http://theshed.hezmatt.org/foreman-export-allah"
16
+
17
+ s.files = `git ls-files -z`.split("\0").reject { |f| f =~ /^(G|spec|Rakefile)/ }
18
+
19
+ s.required_ruby_version = ">= 2.0.0"
20
+
21
+ s.add_runtime_dependency "foreman", "~> 0.60"
22
+
23
+ s.add_development_dependency 'bundler'
24
+ s.add_development_dependency 'github-release'
25
+ s.add_development_dependency 'guard-spork'
26
+ s.add_development_dependency 'guard-rspec'
27
+ s.add_development_dependency 'pry-byebug'
28
+ s.add_development_dependency 'rake', '~> 10.4', '>= 10.4.2'
29
+ # Needed for guard
30
+ s.add_development_dependency 'rb-inotify', '~> 0.9'
31
+ s.add_development_dependency 'rspec', "~> 3.0"
32
+ s.add_development_dependency 'yard'
33
+ end
@@ -0,0 +1,182 @@
1
+ #!/usr/bin/env ruby
2
+ # vim: set nosta noet ts=4 sw=4:
3
+ #encoding: utf-8
4
+
5
+ require 'erb'
6
+ require 'logger'
7
+ require 'pathname'
8
+ require 'foreman/export'
9
+ require 'foreman/cli'
10
+
11
+
12
+ # A Foreman exporter for allah-enhanced daemontools. This exports processes
13
+ # from the Procfile as a hierarchy of directories intended to be run under
14
+ # the supervision of a per-user svscan.
15
+ #
16
+ # This code is based on `foreman-export-daemontools`, which in turn borrowed
17
+ # some of its code from the 'runit' exporter.
18
+ #
19
+ class Foreman::Export::Allah < Foreman::Export::Base
20
+ # The data directory in the project if that exists, otherwise the gem datadir
21
+ DEFAULT_DATADIR = if ENV['FOREMAN_EXPORT_DATADIR']
22
+ Pathname( ENV['FOREMAN_EXPORT_DATADIR'] )
23
+ elsif File.directory?( 'data/foreman-export-allah' )
24
+ Pathname( 'data/foreman-export-allah' )
25
+ elsif path = Gem.datadir( 'foreman-export-allah' )
26
+ Pathname( path )
27
+ else
28
+ raise ScriptError, "can't find the data directory!"
29
+ end
30
+
31
+ # Directory to look in for personal templates
32
+ HOME_TEMPLATEDIR = Pathname( "~/.foreman/templates" ).expand_path
33
+
34
+ # Pattern used to extract inline env variables from the command
35
+ ENV_VARIABLE_REGEX = /([a-zA-Z_]+[a-zA-Z0-9_]*)=(\S+)/
36
+
37
+
38
+ ##
39
+ # The data directory for the gem
40
+ class << self; attr_accessor :datadir; end
41
+ @datadir = DEFAULT_DATADIR
42
+
43
+
44
+ ### Set up the template root
45
+ def initialize( location, engine, options={} ) # :notnew:
46
+ super
47
+ servicedir = self.location or
48
+ raise Foreman::Export::Exception, "No service directory specified."
49
+ @servicedir = Pathname( servicedir )
50
+ @logger = Logger.new( $stderr )
51
+ @template_search_path = [ HOME_TEMPLATEDIR, DEFAULT_DATADIR + 'templates' ]
52
+ @template_search_path.unshift( Pathname(options[:template]) ) if options.key?( :template )
53
+ end
54
+
55
+
56
+ ######
57
+ public
58
+ ######
59
+
60
+ ##
61
+ # The list of directories to search in for templates
62
+ attr_accessor :template_search_path
63
+
64
+ ##
65
+ # The Logger object that gets exporter output
66
+ attr_accessor :logger
67
+
68
+
69
+ ### Main API method -- export the loaded Procfile as supervise service directories
70
+ def export
71
+ app = self.app || File.basename( self.engine.directory )
72
+ user = self.user || app
73
+
74
+ unless @servicedir.exist?
75
+ say "Creating #{@servicedir}..."
76
+ @servicedir.mkpath
77
+ end
78
+
79
+ engine.each_process do |name, process|
80
+ say "Setting up %s-%s service directories..." % [ app, name ]
81
+ count = engine.formation[ name ]
82
+ say " concurrency = #{count}"
83
+ next unless count >= 1
84
+
85
+ # Create a numbered service dir for each instance if there are
86
+ # more than one
87
+ if count != 1
88
+ 1.upto( count ) do |i|
89
+ self.write_servicedir( app, name, i, process, true )
90
+ end
91
+ else
92
+ self.write_servicedir( app, name, 1, process )
93
+ end
94
+ end
95
+ end
96
+
97
+
98
+ ### Write a supervise directory to +targetdir+
99
+ def write_servicedir( app, name, num, process, multi = false )
100
+ procdir = @servicedir + "#{app}-#{name}#{multi ? "-#{num}" : ''}"
101
+
102
+ say "Making directory %s..." % [ procdir ]
103
+ procdir.mkpath
104
+
105
+ # Write the down file to keep the service from spinning up before the user has
106
+ # a chance to look things over
107
+ say " writing the 'down' file"
108
+ write_file( procdir + 'down', '' )
109
+
110
+ # Set up logging
111
+ say " setting up logging..."
112
+ logdir = procdir + 'log'
113
+ logdir.mkpath
114
+ logruntmpl = self.load_template( 'log-run' )
115
+ runfile = logdir + 'run'
116
+ write_file( runfile, logruntmpl.result(binding()) )
117
+ runfile.chmod( 0755 )
118
+
119
+ # Set up the envdir
120
+ say " setting up environment variables..."
121
+ envdir = procdir + 'env'
122
+ envdir.mkpath
123
+ port = engine.port_for( process, num )
124
+ environment_variables = { 'PORT' => port }.
125
+ merge( engine.environment ).
126
+ merge( inline_variables(process.command) )
127
+ environment_variables.each_pair do |var, env|
128
+ write_file( envdir + var, env )
129
+ end
130
+
131
+ # Set up the groupfile
132
+ groupfile = procdir + 'group'
133
+ write_file(groupfile, "#{app}-#{name}\n#{app}\n")
134
+
135
+ # Set up the runfile
136
+ runtmpl = self.load_template( 'run' )
137
+ runfile = procdir + 'run'
138
+ write_file( runfile, runtmpl.result(binding()) )
139
+ runfile.chmod( 0755 )
140
+
141
+ end
142
+
143
+
144
+ ### Load the template for the file named +name+, and return it
145
+ ### as an ERB object.
146
+ def load_template( name )
147
+ template_name = "#{name}.erb"
148
+ template = self.template_search_path.
149
+ map {|dir| dir + template_name }.
150
+ find {|tmpl| tmpl.exist? }
151
+
152
+ template or raise Foreman::Export::Exception,
153
+ "Can't find the %p template in any of: %p" %
154
+ [ name, self.template_search_path.map(&:to_s) ]
155
+
156
+ erbtmpl = ERB.new( template.read, nil, '<%>' )
157
+ end
158
+
159
+
160
+ #########
161
+ protected
162
+ #########
163
+
164
+ ### Override to output to the logger instead of STDERR.
165
+ def say( message )
166
+ @logger.info( '[foreman export]' ) { message }
167
+ end
168
+
169
+
170
+ #######
171
+ private
172
+ #######
173
+
174
+ ### Extract the inline environment variables from +command+ and return them as
175
+ ### a Hash.
176
+ def inline_variables( command )
177
+ pairs = command.scan( ENV_VARIABLE_REGEX )
178
+ return Hash[ *pairs.flatten ]
179
+ end
180
+
181
+
182
+ end # Foreman::Export::Daemontools
metadata ADDED
@@ -0,0 +1,197 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: foreman-export-allah
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Matt Palmer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: foreman
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.60'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.60'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: github-release
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-spork
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '10.4'
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: 10.4.2
107
+ type: :development
108
+ prerelease: false
109
+ version_requirements: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - "~>"
112
+ - !ruby/object:Gem::Version
113
+ version: '10.4'
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: 10.4.2
117
+ - !ruby/object:Gem::Dependency
118
+ name: rb-inotify
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '0.9'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '0.9'
131
+ - !ruby/object:Gem::Dependency
132
+ name: rspec
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: '3.0'
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - "~>"
143
+ - !ruby/object:Gem::Version
144
+ version: '3.0'
145
+ - !ruby/object:Gem::Dependency
146
+ name: yard
147
+ requirement: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ type: :development
153
+ prerelease: false
154
+ version_requirements: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ description:
160
+ email:
161
+ - theshed+foreman-export-allah@hezmatt.org
162
+ executables: []
163
+ extensions: []
164
+ extra_rdoc_files: []
165
+ files:
166
+ - ".gitignore"
167
+ - History.rdoc
168
+ - README.md
169
+ - data/foreman-export-allah/templates/log-run.erb
170
+ - data/foreman-export-allah/templates/run.erb
171
+ - foreman-export-allah.gemspec
172
+ - lib/foreman/export/allah.rb
173
+ homepage: http://theshed.hezmatt.org/foreman-export-allah
174
+ licenses: []
175
+ metadata: {}
176
+ post_install_message:
177
+ rdoc_options: []
178
+ require_paths:
179
+ - lib
180
+ required_ruby_version: !ruby/object:Gem::Requirement
181
+ requirements:
182
+ - - ">="
183
+ - !ruby/object:Gem::Version
184
+ version: 2.0.0
185
+ required_rubygems_version: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - ">="
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ requirements: []
191
+ rubyforge_project:
192
+ rubygems_version: 2.2.2
193
+ signing_key:
194
+ specification_version: 4
195
+ summary: Export a Foreman Procfile to allah services
196
+ test_files: []
197
+ has_rdoc: