Handle INT and TERM signals gracefully; use new dummy shutdown method

This commit is contained in:
Paul van Tilburg 2014-11-15 21:13:31 +01:00
parent de6277601b
commit 963fdc84ef
1 changed files with 9 additions and 0 deletions

9
hued
View File

@ -273,6 +273,10 @@ class Hued
end
end
def shutdown
@log.info "Shutting down..."
end
end # class Hued
# Option parsing
@ -311,9 +315,14 @@ rescue OptionParser::InvalidOption => e
abort opt_parser.to_s
end
# Handle signals
Signal.trap("INT") { EM.stop }
Signal.trap("TERM") { EM.stop }
# Create the main engine and trigger it periodically
hued = Hued.new(options)
EM.run do
EM.add_periodic_timer(10) { hued.execute }
EM.add_periodic_timer(300) { hued.refresh! }
end
hued.shutdown