flapjack 0.6.57 → 0.6.58

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,6 +15,8 @@ options = OpenStruct.new
15
15
  options.config = File.join('etc', 'flapjack_config.yaml')
16
16
  options.daemonize = nil
17
17
 
18
+ @exe = File.basename(__FILE__)
19
+
18
20
  OptionParser.new do |opts|
19
21
  opts.banner = "Usage: flapjack COMMAND [OPTIONS]"
20
22
 
@@ -24,6 +26,7 @@ OptionParser.new do |opts|
24
26
  opts.separator " stop #{" " * 26} stop flapjack"
25
27
  opts.separator " restart #{" " * 23} (re)start flapjack"
26
28
  opts.separator " reload #{" " * 24} reload flapjack configuration"
29
+ opts.separator " status #{" " * 24} see if flapjack is running"
27
30
  opts.separator ""
28
31
  opts.separator "Options"
29
32
 
@@ -68,21 +71,52 @@ daemonize = options.daemonize.nil? ?
68
71
  !!config_env['daemonize'] :
69
72
  options.daemonize
70
73
 
71
- require 'flapjack/coordinator'
72
74
 
73
75
  flapjack_coord = Proc.new {
76
+ require 'flapjack/coordinator'
74
77
  coordinator = Flapjack::Coordinator.new(config)
75
78
  coordinator.start(:signals => true)
76
79
  }
77
80
 
81
+ @runner_opts = { :pid_path => pidfile, :log_path => logfile }
82
+ def get_runner
83
+ Dante::Runner.new(@exe, @runner_opts)
84
+ end
85
+
86
+ def process_exists(pid)
87
+ return unless pid
88
+ begin
89
+ Process.kill(0, pid)
90
+ return true
91
+ rescue Errno::ESRCH
92
+ return false
93
+ end
94
+ end
95
+
96
+ # wait until the specified pid no longer exists, or until a timeout is reached
97
+ def wait_pid_gone(pid, timeout = 30)
98
+ print "waiting for a max of #{timeout} seconds for process #{pid} to exit" if process_exists(pid)
99
+ started_at = Time.now.to_i
100
+ while process_exists(pid)
101
+ break unless (Time.now.to_i - started_at < timeout)
102
+ print '.'
103
+ sleep 1
104
+ end
105
+ puts ''
106
+ return !process_exists(pid)
107
+ end
108
+
109
+ begin
110
+ pid = IO.read(pidfile).chomp.to_i
111
+ rescue StandardError
112
+ pid = nil
113
+ end
114
+
78
115
  case ARGV[0]
79
116
  when "start"
80
- runner = Dante::Runner.new('flapjack', :pid_path => pidfile,
81
- :log_path => logfile)
82
-
117
+ runner = get_runner
83
118
  if runner.daemon_running?
84
119
  puts "Flapjack is already running."
85
- exit 1
86
120
  else
87
121
  print "Flapjack starting..."
88
122
  runner.execute(:daemonize => daemonize) {
@@ -92,37 +126,37 @@ when "start"
92
126
  end
93
127
 
94
128
  when "stop"
95
- runner = Dante::Runner.new('flapjack', :pid_path => pidfile,
96
- :log_path => logfile)
97
-
129
+ runner = get_runner
98
130
  if runner.daemon_running?
99
131
  print "Flapjack stopping..."
100
132
  runner.execute(:kill => true)
101
133
  puts " done."
102
134
  else
103
135
  puts "Flapjack is not running."
104
- exit 1
105
136
  end
137
+ exit 1 unless wait_pid_gone(pid)
106
138
 
107
139
  when "restart"
108
- runner = Dante::Runner.new('flapjack', :pid_path => pidfile,
109
- :log_path => logfile)
140
+ runner = get_runner
141
+ if runner.daemon_running?
142
+ print "Flapjack stopping..."
143
+ runner.execute(:kill => true)
144
+ puts " done."
145
+ end
146
+ exit 1 unless wait_pid_gone(pid)
110
147
 
111
- print "Flapjack restarting..."
112
- runner.execute(:daemonize => true, :restart => true) {
113
- sleep 1 # get connection errors without this... -- might move this to
114
- # be default behaviour when starting jabber gateway
148
+ runner = get_runner
149
+ print "Flapjack starting..."
150
+ runner.execute(:daemonize => daemonize) {
115
151
  flapjack_coord.call
116
152
  }
117
153
  puts " done."
118
154
 
119
155
  when "reload"
120
- runner = Dante::Runner.new('flapjack', :pid_path => pidfile, :log_path => logfile)
121
-
156
+ runner = get_runner
122
157
  if runner.daemon_running?
123
158
  print "Reloading Flapjack configuration..."
124
159
  begin
125
- pid = IO.read(pidfile).chomp.to_i
126
160
  Process.kill('HUP', pid)
127
161
  puts " sent HUP to pid #{pid}."
128
162
  rescue => e
@@ -134,11 +168,10 @@ when "reload"
134
168
  end
135
169
 
136
170
  when "status"
137
- runner = Dante::Runner.new('flapjack', :pid_path => pidfile, :log_path => logfile)
138
-
171
+ runner = get_runner
139
172
  uptime = (runner.daemon_running?) ? Time.now - File.stat(pidfile).ctime : 0
140
173
  if runner.daemon_running?
141
- puts "Flapjack is running: #{uptime}"
174
+ puts "Flapjack is running: pid #{pid}, uptime #{uptime}"
142
175
  else
143
176
  puts "Flapjack is not running"
144
177
  exit 3
@@ -80,7 +80,7 @@ module Flapjack
80
80
  @logger.info "Email sending succeeded"
81
81
  @sent += 1
82
82
  else
83
- @logger.info "Email sending failed"
83
+ @logger.error "Email sending failed"
84
84
  end
85
85
 
86
86
  @logger.info "Email response: #{response.inspect}"
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  module Flapjack
4
- VERSION = "0.6.57"
4
+ VERSION = "0.6.58"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flapjack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.57
4
+ version: 0.6.58
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -465,7 +465,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
465
465
  version: '0'
466
466
  segments:
467
467
  - 0
468
- hash: 782177641495889576
468
+ hash: -3258565481317401030
469
469
  required_rubygems_version: !ruby/object:Gem::Requirement
470
470
  none: false
471
471
  requirements:
@@ -474,7 +474,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
474
474
  version: '0'
475
475
  segments:
476
476
  - 0
477
- hash: 782177641495889576
477
+ hash: -3258565481317401030
478
478
  requirements: []
479
479
  rubyforge_project:
480
480
  rubygems_version: 1.8.23