erlnixify 0.0.2 → 0.0.3

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZDgwYzhmNGFiZDhjMzllYWE2ZjBmZDQ4NjQyM2RmOTA3NzE5MmY1Ng==
4
+ MzMyZjgxN2IxNDliNTAyOWY2MGI0MzQ5MzQyMDkzZTcyNTAwNDE4OQ==
5
5
  data.tar.gz: !binary |-
6
- MDRjNmJjNjVmYmViNWE2ZTliMDJjMmRiOTJhYTM1ZmY5NTU4YThhYQ==
6
+ NTU4NDIzMDA0NDFmNGYzMGNhNTY1MmNlNmMzM2UwZWJmMjY0MTkxZQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YzJjMTA4NzQ3OTRhODgzNTBkOTBkZGJlY2NlNmM2ZGY3OGRmZGMzZjBjNzUw
10
- YWJkNjI5NmFiODJhY2MzZWI1ZmRiNzQ0MGIxOTdiYTkxNzY5YjVhNDYzZGJh
11
- M2VkODEzNjNjZjk5YmVlMGIxYjMxM2NhZjk4YzJkNjdiNzVjMDE=
9
+ N2IxYTAxODg4YWM1MThiYWRjMTcwYzI4NzRkZGNjOTY3NDQ5Njk1ZjEyMGFm
10
+ ZDFkOGMzNjRlNDdlMzMwNGIzY2U0NTUzNTc5MDI1OTI1YWZlNjVjZTYxOWY3
11
+ ODIzODQ1ZTBkNTdkZmU1YWVjZGZlZjkyZmM4YzZhMTY4MzE0ODQ=
12
12
  data.tar.gz: !binary |-
13
- MWY4YWExN2I0ZTBmNzg1M2Y3ZWZhNzcwOGFkY2EzZGI4ZmYxZjY1YjFiMzdl
14
- YjdiMDhiMzdkMDdmMTk1ZmFlMTcxNGQyMzdiNTIzOTljZmEzOWEwYjQ2MmNk
15
- OTZhNGEzNmRjM2E5ZWMzYTg3M2QwMTE1ZDhhNWYzZmI4YmViNTI=
13
+ MWMyNWY2ZWQ4MTNiMjMzMjgwMzU0ZGZlMzZkNjk1Yjk2NjI4OTBmZTVlMWFj
14
+ ODhlNWZiNGMwOTk2YTlhNDY1MTYwNzNiNmMzMTc2Y2I2MGZlYjg1MTU3ZWUw
15
+ NmY1OGRhMzVlNDdiMmFjNzY1NmIwOWMyODQ5NDcwMWQzNzU2ODU=
@@ -1,4 +1,5 @@
1
1
  require 'logger'
2
+ require 'timeout'
2
3
  require 'erlnixify/exceptions'
3
4
 
4
5
  module Erlnixify
@@ -24,27 +25,52 @@ module Erlnixify
24
25
  @log = Logger.new(STDOUT)
25
26
  @log.level = Logger::DEBUG
26
27
 
28
+ end
29
+
30
+ def start
31
+ self.start_deamon
32
+
27
33
  Signal.trap("TERM") do
28
- self.halt_nicely
34
+ # This is going to propagate to the running erlang
35
+ # node. Unfortunately, there is no way to stop that that I
36
+ # have found yet. Hopefully, in the near future we can resolve
37
+ # that.
29
38
  raise NodeError, "SIGTERM recieved, shutting down"
30
39
  end
31
40
 
32
41
  Signal.trap("INT") do
33
- self.halt_nicely
42
+ # This is going to propagate to the running erlang
43
+ # node. Unfortunately, there is no way to stop that that I
44
+ # have found yet. Hopefully, in the near future we can resolve
45
+ # that.
34
46
  raise NodeError, "SIGINT recieved, shutting down"
35
47
  end
36
48
 
37
49
  at_exit { self.external_kill }
50
+
51
+ @log.debug "waiting for #{@settings[:startuptimeout]} seconds for startup"
52
+ sleep @settings[:startuptimeout]
53
+ self.monitor
38
54
  end
39
55
 
40
- def start
41
- @log.debug "starting process"
56
+ def start_deamon
57
+ begin
58
+ self.status
59
+ rescue NodeError => msg
60
+ return self.raw_start_deamon
61
+ end
62
+ raise NodeError, "Already started"
63
+ end
64
+
65
+ def raw_start_deamon
66
+ @log.debug "starting daemon"
42
67
  env = {}
43
68
  env["HOME"] = @settings[:home] if @settings[:home]
44
69
 
45
70
  begin
46
71
  @log.debug "spawning command '#{@command}' with #{env}"
47
72
  @pid = Process.spawn(env, @command)
73
+ Process.detach @pid
48
74
  rescue Errno::ENOENT
49
75
  @log.debug "Invalid command provided, raising error"
50
76
  raise NodeError, "Command does not exist"
@@ -52,7 +78,7 @@ module Erlnixify
52
78
 
53
79
  @log.debug "waiting for #{@settings[:startuptimeout]} seconds for startup"
54
80
  sleep @settings[:startuptimeout]
55
- self.monitor
81
+ self.status
56
82
  end
57
83
 
58
84
  def monitor
@@ -80,15 +106,27 @@ module Erlnixify
80
106
  end
81
107
  end
82
108
 
109
+ def status
110
+ begin
111
+ Timeout.timeout(@settings[:checktimeout]) do
112
+ self.raw_check
113
+ end
114
+ rescue Timeout::Error
115
+ self.halt_nicely
116
+ raise NodeError, "Check command timeout occurred"
117
+ end
118
+ end
119
+
83
120
  def raw_check
84
- @log.debug "Checking the status of Pid #{@pid}"
85
121
  @log.debug "#{@check_command} =~ #{@checkregex}"
86
122
  result = `#{@check_command}`
87
- @log.debug "got #{result}"
123
+ @log.debug "result #{result}"
88
124
  if not (result =~ @checkregex)
89
- @log.debug "Check failed, halting system"
125
+ @log.info "invalid state"
90
126
  self.halt_nicely
91
127
  raise NodeError, "Node check failed"
128
+ else
129
+ @log.info "running"
92
130
  end
93
131
  end
94
132
 
@@ -106,24 +144,39 @@ module Erlnixify
106
144
  end
107
145
  end
108
146
 
109
- def halt_nicely
147
+ def stop
148
+ @log.debug "Executing halt nicely: #{@halt_command}"
110
149
  `#{@halt_command}`
111
- sleep @settings[:checkinterval]
150
+ if not $?
151
+ sleep @settings[:checkinterval]
152
+ else
153
+ raise NodeError, "Got status #{$?}"
154
+ end
155
+ end
156
+
157
+ def halt_nicely
112
158
  if self.is_running?
159
+ @log.debug "Executing halt nicely: #{@halt_command}"
160
+ `#{@halt_command}`
161
+ sleep @settings[:checkinterval]
113
162
  self.halt_brutally
114
163
  end
115
164
  end
116
165
 
117
166
  def halt_brutally
118
- `#{@brutal_halt_command}`
119
- sleep @settings[:checkinterval]
120
167
  if self.is_running?
168
+ @log.debug "Executing halt brutally: #{@brutal_halt_command}"
169
+ `#{@brutal_halt_command}`
170
+ sleep @settings[:checkinterval]
121
171
  self.external_kill
122
172
  end
123
173
  end
124
174
 
125
175
  def external_kill
126
- Process.kill("KILL", @pid) if @pid
176
+ if self.is_running?
177
+ @log.debug "Killing pid: #{@pid}"
178
+ Process.kill("KILL", @pid) if @pid
179
+ end
127
180
  end
128
181
 
129
182
  def interpolate_cmd(cmd)
@@ -8,37 +8,130 @@ module Erlnixify
8
8
  #
9
9
  class Opts
10
10
 
11
- attr_reader :options, :opts
11
+ attr_reader :options, :opts, :command
12
12
 
13
13
  def initialize(args)
14
+ cmd = :start
14
15
  @opts = Slop.parse(args) do
15
16
 
16
17
  banner = "Usage: erlnixify [options]"
17
18
 
18
- on :b, :release=, 'Release Root Directory'
19
- on :e, :erlang=, 'Erlang Root Directory'
20
- on :o, :home=, "The home directory to explicitly set"
21
- on :n, :name=, "The short name of the node to be managed"
22
- on :fullnode=, "The fully qualified node name"
23
- on :m, :command=, "The command to run to start the release"
24
- on :k, :check=, "The command to check if the release is active"
25
- on :r, :checkregex=, "The regex that must match to the output of check command"
26
- on :x, :cookiefile=, "A file that contains the erlang cookie, not needed if cookie is set"
27
- on :i, :cookie=, "The cookie itself, not needed if cookie-file is set"
28
- on(:t, :startuptimeout=,
29
- "The amount of time to let the system startup in seconds",
30
- as: Integer)
31
- on(:a, :checkinterval=,
32
- "How often erlnixify should check to see if the system is still running",
33
- as: Integer)
34
- on(:w, :checktimeout=,
35
- "The longest time a check can run, defaults to 30 seconds",
36
- as: Integer)
37
- on :c, :config=, "A file that contains the YAML based config for this system"
38
- on :v, :version, "Show the Version"
19
+ command 'startdeamon' do
20
+ on :b, :release=, 'Release Root Directory'
21
+ on :e, :erlang=, 'Erlang Root Directory'
22
+ on :o, :home=, "The home directory to explicitly set"
23
+ on :n, :name=, "The short name of the node to be managed"
24
+ on :fullnode=, "The fully qualified node name"
25
+ on :m, :command=, "The command to run to start the release"
26
+ on :k, :check=, "The command to check if the release is active"
27
+ on :r, :checkregex=, "The regex that must match to the output of check command"
28
+ on :x, :cookiefile=, "A file that contains the erlang cookie, not needed if cookie is set"
29
+ on :i, :cookie=, "The cookie itself, not needed if cookie-file is set"
30
+ on(:t, :startuptimeout=,
31
+ "The amount of time to let the system startup in seconds",
32
+ as: Integer)
33
+ on(:a, :checkinterval=,
34
+ "How often erlnixify should check to see if the system is still running",
35
+ as: Integer)
36
+ on(:w, :checktimeout=,
37
+ "The longest time a check can run, defaults to 30 seconds",
38
+ as: Integer)
39
+ on :c, :config=, "A file that contains the YAML based config for this system"
40
+ on :v, :version, "Show the Version"
41
+
42
+ run do |opts, args|
43
+ cmd = :startdeamon
44
+ end
45
+ end
46
+
47
+ command 'start' do
48
+ on :b, :release=, 'Release Root Directory'
49
+ on :e, :erlang=, 'Erlang Root Directory'
50
+ on :o, :home=, "The home directory to explicitly set"
51
+ on :n, :name=, "The short name of the node to be managed"
52
+ on :fullnode=, "The fully qualified node name"
53
+ on :m, :command=, "The command to run to start the release"
54
+ on :k, :check=, "The command to check if the release is active"
55
+ on :r, :checkregex=, "The regex that must match to the output of check command"
56
+ on :x, :cookiefile=, "A file that contains the erlang cookie, not needed if cookie is set"
57
+ on :i, :cookie=, "The cookie itself, not needed if cookie-file is set"
58
+ on(:t, :startuptimeout=,
59
+ "The amount of time to let the system startup in seconds",
60
+ as: Integer)
61
+ on(:a, :checkinterval=,
62
+ "How often erlnixify should check to see if the system is still running",
63
+ as: Integer)
64
+ on(:w, :checktimeout=,
65
+ "The longest time a check can run, defaults to 30 seconds",
66
+ as: Integer)
67
+ on :c, :config=, "A file that contains the YAML based config for this system"
68
+ on :v, :version, "Show the Version"
69
+
70
+ run do |opts, args|
71
+ cmd = :start
72
+ end
73
+ end
74
+
75
+ command 'stop' do
76
+ on :b, :release=, 'Release Root Directory'
77
+ on :e, :erlang=, 'Erlang Root Directory'
78
+ on :o, :home=, "The home directory to explicitly set"
79
+ on :n, :name=, "The short name of the node to be managed"
80
+ on :fullnode=, "The fully qualified node name"
81
+ on :m, :command=, "The command to run to start the release"
82
+ on :k, :check=, "The command to check if the release is active"
83
+ on :r, :checkregex=, "The regex that must match to the output of check command"
84
+ on :x, :cookiefile=, "A file that contains the erlang cookie, not needed if cookie is set"
85
+ on :i, :cookie=, "The cookie itself, not needed if cookie-file is set"
86
+ on(:t, :startuptimeout=,
87
+ "The amount of time to let the system startup in seconds",
88
+ as: Integer)
89
+ on(:a, :checkinterval=,
90
+ "How often erlnixify should check to see if the system is still running",
91
+ as: Integer)
92
+ on(:w, :checktimeout=,
93
+ "The longest time a check can run, defaults to 30 seconds",
94
+ as: Integer)
95
+ on :c, :config=, "A file that contains the YAML based config for this system"
96
+ on :v, :version, "Show the Version"
97
+
98
+ run do |opts, args|
99
+ cmd = :stop
100
+ end
101
+ end
102
+
103
+ command 'status' do
104
+ on :b, :release=, 'Release Root Directory'
105
+ on :e, :erlang=, 'Erlang Root Directory'
106
+ on :o, :home=, "The home directory to explicitly set"
107
+ on :n, :name=, "The short name of the node to be managed"
108
+ on :fullnode=, "The fully qualified node name"
109
+ on :m, :command=, "The command to run to start the release"
110
+ on :k, :check=, "The command to check if the release is active"
111
+ on :r, :checkregex=, "The regex that must match to the output of check command"
112
+ on :x, :cookiefile=, "A file that contains the erlang cookie, not needed if cookie is set"
113
+ on :i, :cookie=, "The cookie itself, not needed if cookie-file is set"
114
+ on(:t, :startuptimeout=,
115
+ "The amount of time to let the system startup in seconds",
116
+ as: Integer)
117
+ on(:a, :checkinterval=,
118
+ "How often erlnixify should check to see if the system is still running",
119
+ as: Integer)
120
+ on(:w, :checktimeout=,
121
+ "The longest time a check can run, defaults to 30 seconds",
122
+ as: Integer)
123
+ on :c, :config=, "A file that contains the YAML based config for this system"
124
+ on :v, :version, "Show the Version"
125
+
126
+ run do |opts, args|
127
+ cmd = :status
128
+ end
129
+ end
130
+
39
131
  end
40
132
 
41
- @options = opts.to_hash
133
+ @options = opts.to_hash(true)
134
+ @command = cmd
42
135
  end
43
136
  end
44
137
 
@@ -14,14 +14,13 @@ module Erlnixify
14
14
  CHECK_COMMAND = "erlang statistics [reductions]"
15
15
  CHECK_REGEX = "^{\\d+, \\d+}$"
16
16
 
17
- def initialize(opts)
18
- @options = opts
19
- config = @options.options[:config]
17
+ def initialize(options)
18
+ config = options[:config]
20
19
 
21
20
  @settings = self.default_settings
22
21
 
23
22
  self.load! config if config
24
- self.merge(@options.options)
23
+ self.merge(options)
25
24
  self.post_settings_setup
26
25
  end
27
26
 
@@ -1,3 +1,3 @@
1
1
  module Erlnixify
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/erlnixify.rb CHANGED
@@ -9,34 +9,52 @@ module Erlnixify
9
9
  class Main
10
10
  def self.main(args)
11
11
  @opts = Erlnixify::Opts.new(args)
12
-
13
- if @opts.opts.version?
12
+ options = nil
13
+ options = @opts.options[@opts.command]
14
+ if options[:version]
14
15
  puts Erlnixify::VERSION
15
16
  exit 0
16
17
  end
17
18
 
18
- if not @opts.opts.command?
19
+ if not options[:command]
19
20
  puts "missing command option, this is required"
20
21
  puts @opts.opts.help
21
22
  exit 1
22
23
  end
23
24
 
24
- if not @opts.opts.name?
25
+ if not options[:name]
25
26
  puts "missing name option"
26
27
  puts @opts.opts.help
27
28
  exit 1
28
29
  end
29
30
 
30
- if not (@opts.opts.cookie? || @opts.opts.cookiefile?)
31
+ if not (options[:cookie] || options[:cookiefile])
31
32
  puts "missing both cookie and cookiefile options, at least one is required"
32
33
  puts @opts.opts.help
33
34
  exit 1
34
35
  end
35
36
 
36
- @settings = Erlnixify::Settings.new(@opts)
37
- @process = Erlnixify::Node.new(@settings)
37
+ @settings = Erlnixify::Settings.new(options)
38
+ @node = Erlnixify::Node.new(@settings)
38
39
  begin
39
- @process.start
40
+ case @opts.command
41
+ when :start
42
+ @node.start
43
+ when :startdeamon
44
+ @node.start_deamon
45
+ exit 0
46
+ when :stop
47
+ @node.stop
48
+ when :status
49
+ begin
50
+ @node.status
51
+ rescue Exception => msg
52
+ puts "stopped", msg
53
+ exit 127
54
+ end
55
+ else
56
+ @node.start
57
+ end
40
58
  rescue Erlnixify::NodeError
41
59
  exit 127
42
60
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erlnixify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Merritt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-24 00:00:00.000000000 Z
11
+ date: 2013-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler