foreman-export-initd 0.0.5 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1b705ba7b9d2252a400554e266f8ab160b51cc57
4
- data.tar.gz: 5e6d7ec59532f56545b35e771bb26c4ce5b7847a
3
+ metadata.gz: dee0c30fbc1a2ab4e63333ac1c0fb6a3da43990b
4
+ data.tar.gz: 885e3be0f73c0d93ad3fbfcceaf012f979a6862c
5
5
  SHA512:
6
- metadata.gz: 8a83f285439c023f13c7e3a99d34617fb45dba2e1d660f2d0a0d78d3265038129dd78ec0f29c0d4c8c579814940162d32992706f518c08fcf5a92e2e979d457f
7
- data.tar.gz: 6dc00a5c79ffd30bf42ac41bde0f5b3f2a36da55f42041b3066317b994ba67fe57dbd1b4cacff4bcc3d493ddc2a703845ff6a36d0d00d4a594633ec66f004db7
6
+ metadata.gz: 08abc5542da2835c7682d678ac1eedee0646e2781407ab736ab252ec2c3a61cb61d49c62b6e2c431d81d86110763e946da065d1f9305d6df504c4806d7b6491b
7
+ data.tar.gz: 8e0d70cee0d439db9c4dd63e954555374f3d9d55e2b7c80097d35371fb33dc5e558364587ee9138427b8a21366b7534d80a59cb32b10de83f1e2eccc45ab63ff
data/README.md CHANGED
@@ -5,6 +5,6 @@
5
5
  Usage:
6
6
  ```
7
7
  gem install foreman-export-initd
8
- foreman-initd export initd /etc/init.d
9
- foreman-initd export initd-monit /etc/monit/conf.d
8
+ foreman export initd /etc/init.d
9
+ foreman export initd-monit /etc/monit/conf.d
10
10
  ```
@@ -5,8 +5,9 @@ module Initd
5
5
  require 'shellwords'
6
6
  require 'foreman/export'
7
7
  require 'foreman/cli'
8
- require 'foreman/export/initd'
9
- require 'foreman/export/initd_monit'
10
8
  require 'initd/script'
11
9
  require 'initd/monit_config'
10
+ require 'initd/export'
11
+ require 'foreman/export/initd'
12
+ require 'foreman/export/initd_monit'
12
13
  end
@@ -1,40 +1,23 @@
1
1
  require 'foreman-export-initd'
2
2
 
3
3
  class Foreman::Export::Initd < Foreman::Export::Base
4
+ include Initd::Export
4
5
 
5
6
  def export
6
7
  error('Must specify a location') unless location
8
+ setup
7
9
 
8
- cwd = Pathname.new(engine.root)
9
- export_path = Pathname.new(location)
10
- say "creating: #{export_path}"
11
- FileUtils.mkdir_p(export_path)
12
-
13
- existing = []
14
- Dir.glob export_path.join("#{app}-*") do |filename|
15
- contents = File.new(filename, 'r').read
16
- existing.push(filename) if contents.match(/# Autogenerated by foreman/)
17
- end
18
-
19
- exported = []
20
10
  engine.each_process do |name, process|
21
- path = export_path.join("#{app}-#{name}")
22
- args = process.command.split(/\s+/)
23
- script = Pathname.new(cwd).join(args.shift)
24
- concurrency = engine.formation[name]
11
+ args = Shellwords.split(process.command)
12
+ script = Pathname.new(engine.root).join(args.shift)
13
+ path = path(name)
14
+ concurrency = concurrency(name)
25
15
  if concurrency > 0
26
16
  say 'Warning: Initd exporter ignores concurrency > 1' if concurrency > 1
27
17
  contents = Initd::Script.new(path, script, args, user).content
28
- write_file(path, contents)
29
- File.chmod(0755, path)
30
- exported.push path.to_s
18
+ export_file path, contents
31
19
  end
32
20
  end
33
-
34
- to_remove = existing - exported
35
- to_remove.each do |filename|
36
- say 'removing ' + filename
37
- File.unlink filename
38
- end
21
+ cleanup
39
22
  end
40
23
  end
@@ -1,38 +1,20 @@
1
1
  require 'foreman-export-initd'
2
2
 
3
3
  class Foreman::Export::InitdMonit < Foreman::Export::Base
4
+ include Initd::Export
4
5
 
5
6
  def export
6
7
  error('Must specify a location') unless location
7
-
8
- cwd = Pathname.new(engine.root)
9
- export_path = Pathname.new(location)
10
- say "creating: #{export_path}"
11
- FileUtils.mkdir_p(export_path)
12
-
13
- existing = []
14
- Dir.glob export_path.join("#{app}-*") do |filename|
15
- contents = File.new(filename, 'r').read
16
- existing.push(filename) if contents.match(/# Autogenerated by foreman/)
17
- end
18
-
19
- exported = []
8
+ setup
20
9
  engine.each_process do |name, process|
21
- path = export_path.join("#{app}-#{name}")
22
- concurrency = engine.formation[name]
10
+ concurrency = concurrency name
11
+ path = path name
23
12
  if concurrency > 0
24
13
  say 'Warning: Initd exporter ignores concurrency > 1' if concurrency > 1
25
14
  contents = Initd::MonitConfig.new(app, path).content
26
- write_file(path, contents)
27
- File.chmod(0755, path)
28
- exported.push path.to_s
15
+ export_file path, contents
29
16
  end
30
17
  end
31
-
32
- to_remove = existing - exported
33
- to_remove.each do |filename|
34
- say 'removing ' + filename
35
- File.unlink filename
36
- end
18
+ cleanup
37
19
  end
38
20
  end
@@ -0,0 +1,36 @@
1
+ module Initd::Export
2
+
3
+ def export_path
4
+ Pathname.new location
5
+ end
6
+
7
+ def setup
8
+ @exported = []
9
+ say "creating: #{export_path}"
10
+ FileUtils.mkdir_p(export_path)
11
+ end
12
+
13
+ def cleanup
14
+ Dir.glob export_path.join("#{app}-*") do |filename|
15
+ contents = File.new(filename, 'r').read
16
+ next unless contents.match(/# Autogenerated by foreman/)
17
+ next if @exported.include? filename.to_s
18
+ say 'removing ' + filename
19
+ File.unlink filename
20
+ end
21
+ end
22
+
23
+ def export_file (path, contents)
24
+ write_file(path, contents)
25
+ File.chmod(0755, path)
26
+ @exported.push path.to_s
27
+ end
28
+
29
+ def concurrency(name)
30
+ engine.formation[name]
31
+ end
32
+
33
+ def path(name)
34
+ export_path.join("#{app}-#{name}")
35
+ end
36
+ end
data/lib/initd/script.rb CHANGED
@@ -11,14 +11,14 @@ class Initd::Script
11
11
  @daemon = {
12
12
  :name => name,
13
13
  :script => script,
14
- :args => args.join(' '),
14
+ :args => args,
15
15
  :user => user,
16
16
  }
17
17
  @description = name
18
18
  end
19
19
 
20
20
  def name
21
- path.basename.to_s
21
+ @path.basename.to_s
22
22
  end
23
23
 
24
24
  def pidfile
@@ -1,5 +1,5 @@
1
1
  # Autogenerated by foreman
2
- check process <%= name %> with pidfile <%= pidfile %>
2
+ check process <%= name.shellescape %> with pidfile <%= pidfile.to_s.shellescape %>
3
3
  group <%= app %>
4
4
  start program = "/etc/init.d/<%= name %> start"
5
5
  stop program = "/etc/init.d/<%= name %> stop"
data/templates/script.erb CHANGED
@@ -12,13 +12,12 @@
12
12
  # Description: <%= description %>
13
13
  ### END INIT INFO
14
14
 
15
- NAME=<%= name %>
16
- DESC=<%= description %>
17
- DAEMON=<%= daemon[:script] %>
18
- DAEMON_USER=<%= daemon[:user] %>
19
- PIDDIR=<%= pidfile.dirname %>
20
- PIDFILE=<%= pidfile %>
21
- DAEMON_ARGS=<%= daemon[:args].shellescape %>
15
+ NAME=<%= Shellwords.escape name %>
16
+ DESC=<%= Shellwords.escape description %>
17
+ DAEMON=<%= Shellwords.escape daemon[:script].to_s %>
18
+ DAEMON_USER=<%= Shellwords.escape daemon[:user] %>
19
+ PIDDIR=<%= Shellwords.escape pidfile.dirname.to_s %>
20
+ PIDFILE=<%= Shellwords.escape pidfile.to_s %>
22
21
 
23
22
  test -x ${DAEMON} || exit 0
24
23
  set -e
@@ -29,7 +28,7 @@ case "${1}" in
29
28
  start)
30
29
  log_daemon_msg "Starting ${DESC}" "${NAME}"
31
30
  mkdir -p ${PIDDIR}
32
- if (start-stop-daemon --start --make-pidfile --background --pidfile $PIDFILE --chuid $DAEMON_USER --exec $DAEMON -- $DAEMON_ARGS); then
31
+ if (start-stop-daemon --start --make-pidfile --background --pidfile $PIDFILE --chuid $DAEMON_USER --exec $DAEMON -- <%= Shellwords.join daemon[:args] %>); then
33
32
  log_end_msg 0
34
33
  else
35
34
  log_end_msg 1
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman-export-initd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomasz Durka
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-12 00:00:00.000000000 Z
12
+ date: 2013-12-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: foreman
@@ -53,20 +53,6 @@ dependencies:
53
53
  - - ">="
54
54
  - !ruby/object:Gem::Version
55
55
  version: '2.0'
56
- - !ruby/object:Gem::Dependency
57
- name: rake
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- version: 0.4.3
63
- type: :development
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- version: 0.4.3
70
56
  - !ruby/object:Gem::Dependency
71
57
  name: fakefs
72
58
  requirement: !ruby/object:Gem::Requirement
@@ -83,16 +69,15 @@ dependencies:
83
69
  version: 0.4.3
84
70
  description: init.d export scripts for foreman
85
71
  email: tomasz@durka.pl
86
- executables:
87
- - foreman-initd
72
+ executables: []
88
73
  extensions: []
89
74
  extra_rdoc_files:
90
75
  - README.md
91
76
  files:
92
- - bin/foreman-initd
93
77
  - lib/foreman/export/initd.rb
94
78
  - lib/foreman/export/initd_monit.rb
95
79
  - lib/foreman-export-initd.rb
80
+ - lib/initd/export.rb
96
81
  - lib/initd/monit_config.rb
97
82
  - lib/initd/script.rb
98
83
  - templates/monit_config.erb
data/bin/foreman-initd DELETED
@@ -1,8 +0,0 @@
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