foreman-export-initd 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5fa1af670d3fb6140967c695325e8edd333407a7
4
+ data.tar.gz: 2b9e6a65673dbf85bc3b1e8613a0e52d38a24147
5
+ SHA512:
6
+ metadata.gz: 34cbbbcd711409c10d6019e341bdc734f12363471c163ba2c2092b2bf0ee897502e342f5a1f590a695eb74e35922f855237cbe7249a9cf212a0d97e2c3c66995
7
+ data.tar.gz: 263258bea3f9f75db0380596e427aa7ba66d5360f3d48f4db348703c37dac0782e6ad07d8b0458fe209140c1e96f68ad2dc86ea1447fd0abfe03bc2fdbb98bae
data/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # Initd script foreman exporter
2
+
3
+ Usage:
4
+ ```
5
+ gem install foreman-export-initd
6
+ foreman-initd export initd ...
7
+ ```
data/bin/foreman-initd ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
5
+ require 'foreman-export-initd'
6
+ require 'foreman/cli'
7
+
8
+ Foreman::CLI.start
@@ -0,0 +1,10 @@
1
+ module Initd
2
+ require 'fileutils'
3
+ require 'pathname'
4
+ require 'erb'
5
+ require 'shellwords'
6
+ require 'foreman/export'
7
+ require 'foreman/cli'
8
+ require 'foreman/export/initd'
9
+ require 'initd/script'
10
+ end
@@ -0,0 +1,36 @@
1
+ class Foreman::Export::Initd < Foreman::Export::Base
2
+
3
+ def export
4
+ error('Must specify a location') unless location
5
+
6
+ cwd = Pathname.new(engine.root)
7
+ export_to = Pathname.new(location)
8
+
9
+ existing = []
10
+ Dir.glob export_to.join("#{app}-*") do |filename|
11
+ contents = File.new(filename, 'r').read
12
+ existing.push(filename) if contents.match(/# Autogenerated by foreman/)
13
+ end
14
+
15
+ exported = []
16
+ engine.each_process do |name, process|
17
+ path = export_to.join("#{app}-#{name}")
18
+ args = process.command.split(/\s+/)
19
+ script = Pathname.new(cwd).join(args.shift)
20
+ concurrency = engine.formation[name]
21
+ if concurrency > 0
22
+ say 'Warning: Initd exporter ignores concurrency > 1' if concurrency > 1
23
+ initscript = Initd::Script.new path, script, args, user
24
+ say 'Exporting ' + path.to_s
25
+ initscript.export
26
+ exported.push path.to_s
27
+ end
28
+ end
29
+
30
+ to_remove = existing - exported
31
+ to_remove.each do |filename|
32
+ say 'Removing ' + filename
33
+ File.unlink filename
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,31 @@
1
+ class Initd::Script
2
+
3
+ attr_reader :daemon, :name, :description
4
+
5
+ def templates_dir
6
+ Pathname.new(__FILE__).dirname.dirname.dirname.join('templates')
7
+ end
8
+
9
+ def initialize(path, script, args, user)
10
+ @path = path
11
+ @daemon = {
12
+ :name => path.basename,
13
+ :script => script,
14
+ :args => args.join(' '),
15
+ :user => user
16
+ }
17
+ @name = @daemon[:name]
18
+ @description = @daemon[:name]
19
+ end
20
+
21
+ def content
22
+ template = templates_dir.join('script.erb')
23
+ ERB.new(template.read, nil, '<>').result(binding)
24
+ end
25
+
26
+ def export
27
+ FileUtils.mkdir_p(File.dirname(@path))
28
+ File.new(@path, 'w').write(content)
29
+ File.chmod(0755, @path)
30
+ end
31
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: foreman-export-initd
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tomasz Durka
8
+ - Cargomedia
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-12-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: foreman
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: 0.59.0
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: 0.59.0
28
+ description: init.d export scripts for foreman
29
+ email: tomasz@durka.pl
30
+ executables:
31
+ - foreman-initd
32
+ extensions: []
33
+ extra_rdoc_files:
34
+ - README.md
35
+ files:
36
+ - bin/foreman-initd
37
+ - lib/foreman/export/initd.rb
38
+ - lib/foreman-export-initd.rb
39
+ - lib/initd/script.rb
40
+ - README.md
41
+ homepage: http://github.com/tomaszdurka/foreman-export-initd
42
+ licenses: []
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 2.1.11
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: init.d export scripts for foreman
64
+ test_files: []