Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed pidfile option
  • Loading branch information
NOX73 committed Dec 22, 2012
1 parent 2a8c8a4 commit a256bbb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
25 changes: 16 additions & 9 deletions lib/mail_sandbox/runner.rb
@@ -1,5 +1,6 @@
require "eventmachine"
require 'optparse'
require 'simple_pid'
require 'fileutils'

module MailSandbox
Expand All @@ -26,8 +27,8 @@ def option_parse
config.daemonize = f
end

opts.on("-P", "--pid", "File to store PID") do |f|
config.pidfile = f
opts.on("-P", "--pid FILE", "File to store PID") do |f|
config.pidfile = ::File.expand_path(f)
end

end.parse!
Expand All @@ -47,7 +48,7 @@ def configure
when :debug then Logger::DEBUG
end
STDOUT.sync = true
MailSandbox::Signals.trap
MailSandbox::Signals.trap(self)
MailSandbox::Server.parms = config.server_params
end

Expand All @@ -69,19 +70,25 @@ def env
end

def write_pidfile
SimplePid.new(config.pidfile)
@simple_pid = SimplePid.new(config.pidfile)

if pid.exists?
unless pid.running?
pid.cleanup
pid.write!
if @simple_pid.exists?
unless @simple_pid.running?
@simple_pid.cleanup
@simple_pid.write!
end
else
pid.write!
@simple_pid.write!
end

end

def terminate
MailSandbox.logger.info "Got quit/terminate signal. Bye."
@simple_pid.cleanup
exit
end

end

end
8 changes: 4 additions & 4 deletions lib/mail_sandbox/signals.rb
@@ -1,14 +1,14 @@
module MailSandbox
class Signals

def self.trap
def self.trap(server)

%w'TERM QUIT'.each do |signal|
Signal.trap(signal) do
MailSandbox.logger.info "Got #{signal} signal. Bye."
exit
server.terminate
end

end

end

end
Expand Down

0 comments on commit a256bbb

Please sign in to comment.