foreman-export-initd 0.0.1 → 0.0.2

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: 5fa1af670d3fb6140967c695325e8edd333407a7
4
- data.tar.gz: 2b9e6a65673dbf85bc3b1e8613a0e52d38a24147
3
+ metadata.gz: 5b55c6cfd6385fa58a2d609261bdcf3ca1524bac
4
+ data.tar.gz: 54d1de32f7968249ae105cdc1514c3ca8347316e
5
5
  SHA512:
6
- metadata.gz: 34cbbbcd711409c10d6019e341bdc734f12363471c163ba2c2092b2bf0ee897502e342f5a1f590a695eb74e35922f855237cbe7249a9cf212a0d97e2c3c66995
7
- data.tar.gz: 263258bea3f9f75db0380596e427aa7ba66d5360f3d48f4db348703c37dac0782e6ad07d8b0458fe209140c1e96f68ad2dc86ea1447fd0abfe03bc2fdbb98bae
6
+ metadata.gz: b4231b9361b8bab104034c25fede661d8ea0f3811349de710484335c7b98d7edfa9bf2dc5f4c027188b7997162733116d9fa20910a7f3017c04006733f96b692
7
+ data.tar.gz: e940adf091390ec0c687a2a8fe34533c3403cda5d25010caf85fee956529ac06155bc7dbee2a6220648e922aad6015e177698d13b1d640c8b87b316dc42739e0
data/README.md CHANGED
@@ -1,7 +1,10 @@
1
1
  # Initd script foreman exporter
2
2
 
3
+ [![Build Status](https://travis-ci.org/tomaszdurka/foreman-export-initd.png?branch=master)](https://travis-ci.org/tomaszdurka/foreman-export-initd)
4
+
3
5
  Usage:
4
6
  ```
5
7
  gem install foreman-export-initd
6
- foreman-initd export initd ...
8
+ foreman-initd export initd /etc/init.d
9
+ foreman-initd export initd-monit /etc/monit/conf.d
7
10
  ```
@@ -6,5 +6,7 @@ module Initd
6
6
  require 'foreman/export'
7
7
  require 'foreman/cli'
8
8
  require 'foreman/export/initd'
9
+ require 'foreman/export/initd_monit'
9
10
  require 'initd/script'
11
+ require 'initd/monit_config'
10
12
  end
@@ -4,25 +4,27 @@ class Foreman::Export::Initd < Foreman::Export::Base
4
4
  error('Must specify a location') unless location
5
5
 
6
6
  cwd = Pathname.new(engine.root)
7
- export_to = Pathname.new(location)
7
+ export_path = Pathname.new(location)
8
+ say "creating: #{export_path}"
9
+ FileUtils.mkdir_p(export_path)
8
10
 
9
11
  existing = []
10
- Dir.glob export_to.join("#{app}-*") do |filename|
12
+ Dir.glob export_path.join("#{app}-*") do |filename|
11
13
  contents = File.new(filename, 'r').read
12
14
  existing.push(filename) if contents.match(/# Autogenerated by foreman/)
13
15
  end
14
16
 
15
17
  exported = []
16
18
  engine.each_process do |name, process|
17
- path = export_to.join("#{app}-#{name}")
19
+ path = export_path.join("#{app}-#{name}")
18
20
  args = process.command.split(/\s+/)
19
21
  script = Pathname.new(cwd).join(args.shift)
20
22
  concurrency = engine.formation[name]
21
23
  if concurrency > 0
22
24
  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
25
+ contents = Initd::Script.new(path, script, args, user).content
26
+ write_file(path, contents)
27
+ File.chmod(0755, path)
26
28
  exported.push path.to_s
27
29
  end
28
30
  end
@@ -0,0 +1,36 @@
1
+ class Foreman::Export::InitdMonit < Foreman::Export::Base
2
+
3
+ def export
4
+ error('Must specify a location') unless location
5
+
6
+ cwd = Pathname.new(engine.root)
7
+ export_path = Pathname.new(location)
8
+ say "creating: #{export_path}"
9
+ FileUtils.mkdir_p(export_path)
10
+
11
+ existing = []
12
+ Dir.glob export_path.join("#{app}-*") do |filename|
13
+ contents = File.new(filename, 'r').read
14
+ existing.push(filename) if contents.match(/# Autogenerated by foreman/)
15
+ end
16
+
17
+ exported = []
18
+ engine.each_process do |name, process|
19
+ path = export_path.join("#{app}-#{name}")
20
+ concurrency = engine.formation[name]
21
+ if concurrency > 0
22
+ say 'Warning: Initd exporter ignores concurrency > 1' if concurrency > 1
23
+ contents = Initd::MonitConfig.new(path).content
24
+ write_file(path, contents)
25
+ File.chmod(0755, path)
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,25 @@
1
+ class Initd::MonitConfig
2
+
3
+ attr_reader :path
4
+
5
+ def templates_dir
6
+ Pathname.new(__FILE__).dirname.dirname.dirname.join('templates')
7
+ end
8
+
9
+ def initialize(path)
10
+ @path = path
11
+ end
12
+
13
+ def name
14
+ @path.basename.to_s
15
+ end
16
+
17
+ def pidfile
18
+ Pathname.new('/var/run').join(name).join("#{name}.pid")
19
+ end
20
+
21
+ def content
22
+ template = templates_dir.join('monit_config.erb')
23
+ ERB.new(template.read, nil, '<>').result(binding)
24
+ end
25
+ end
data/lib/initd/script.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  class Initd::Script
2
2
 
3
- attr_reader :daemon, :name, :description
3
+ attr_reader :daemon, :path, :description
4
4
 
5
5
  def templates_dir
6
6
  Pathname.new(__FILE__).dirname.dirname.dirname.join('templates')
@@ -9,23 +9,24 @@ class Initd::Script
9
9
  def initialize(path, script, args, user)
10
10
  @path = path
11
11
  @daemon = {
12
- :name => path.basename,
12
+ :name => name,
13
13
  :script => script,
14
14
  :args => args.join(' '),
15
- :user => user
15
+ :user => user,
16
16
  }
17
- @name = @daemon[:name]
18
- @description = @daemon[:name]
17
+ @description = name
18
+ end
19
+
20
+ def name
21
+ path.basename.to_s
22
+ end
23
+
24
+ def pidfile
25
+ Pathname.new('/var/run').join(@daemon[:name]).join("#{@daemon[:name]}.pid")
19
26
  end
20
27
 
21
28
  def content
22
29
  template = templates_dir.join('script.erb')
23
30
  ERB.new(template.read, nil, '<>').result(binding)
24
31
  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
32
  end
@@ -0,0 +1,5 @@
1
+ # Autogenerated by foreman
2
+ check process <%= name %> with pidfile <%= pidfile %>
3
+ start program = "/etc/init.d/<%= name %> start"
4
+ stop program = "/etc/init.d/<%= name %> stop"
5
+ if 25 restarts within 50 cycles then timeout
@@ -0,0 +1,58 @@
1
+ #!/bin/sh
2
+
3
+ # Autogenerated by foreman
4
+
5
+ ### BEGIN INIT INFO
6
+ # Provides: <%= name %>
7
+ # Required-Start: $syslog
8
+ # Required-Stop: $syslog
9
+ # Default-Start: 2 3 4 5
10
+ # Default-Stop: 0 1 6
11
+ # Short-Description: <%= name %>
12
+ # Description: <%= description %>
13
+ ### END INIT INFO
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 %>
22
+
23
+ test -x ${DAEMON} || exit 0
24
+ set -e
25
+ . /lib/lsb/init-functions
26
+
27
+
28
+ case "${1}" in
29
+ start)
30
+ log_daemon_msg "Starting ${DESC}" "${NAME}"
31
+ mkdir -p ${PIDDIR}
32
+ if (start-stop-daemon --start --make-pidfile --background --pidfile $PIDFILE --chuid $DAEMON_USER --exec $DAEMON -- $DAEMON_ARGS); then
33
+ log_end_msg 0
34
+ else
35
+ log_end_msg 1
36
+ fi
37
+ ;;
38
+ stop)
39
+ log_daemon_msg "Stopping ${DESC}" "${NAME}"
40
+ if (start-stop-daemon --stop --oknodo --retry 20 --pidfile $PIDFILE --chuid $DAEMON_USER); then
41
+ log_end_msg 0
42
+ else
43
+ log_end_msg 1
44
+ fi
45
+ ;;
46
+ status)
47
+ status_of_proc -p ${PIDFILE} ${DAEMON} ${NAME}
48
+ ;;
49
+ restart)
50
+ ${0} stop
51
+ ${0} start
52
+ ;;
53
+ *)
54
+ echo "Usage: ${0} {start|stop|status|restart}" >&2
55
+ ;;
56
+ esac
57
+
58
+ exit 0
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.1
4
+ version: 0.0.2
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-10 00:00:00.000000000 Z
12
+ date: 2013-12-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: foreman
@@ -35,8 +35,12 @@ extra_rdoc_files:
35
35
  files:
36
36
  - bin/foreman-initd
37
37
  - lib/foreman/export/initd.rb
38
+ - lib/foreman/export/initd_monit.rb
38
39
  - lib/foreman-export-initd.rb
40
+ - lib/initd/monit_config.rb
39
41
  - lib/initd/script.rb
42
+ - templates/monit_config.erb
43
+ - templates/script.erb
40
44
  - README.md
41
45
  homepage: http://github.com/tomaszdurka/foreman-export-initd
42
46
  licenses: []