Class: Slacky::Daemon
- Inherits:
-
Object
- Object
- Slacky::Daemon
- Defined in:
- lib/slacky/daemon.rb
Instance Method Summary collapse
- #cleanup ⇒ Object
-
#initialize(config, bot_class) ⇒ Daemon
constructor
A new instance of Daemon.
- #start(daemonize = true) ⇒ Object
Constructor Details
#initialize(config, bot_class) ⇒ Daemon
Returns a new instance of Daemon.
4 5 6 7 8 9 |
# File 'lib/slacky/daemon.rb', line 4 def initialize(config, bot_class) @config = config @bot_class = bot_class @active = true @running = false end |
Instance Method Details
#cleanup ⇒ Object
37 38 39 |
# File 'lib/slacky/daemon.rb', line 37 def cleanup delete_pid end |
#start(daemonize = true) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/slacky/daemon.rb', line 11 def start(daemonize = true) Process.daemon if daemonize write_pid [ 'HUP', 'INT', 'QUIT', 'TERM' ].each do |sig| Signal.trap(sig) do @config.log "Interrupted with signal: #{sig}" kill end end begin Thread.abort_on_exception = true @slackthread = Thread.new do bot = Bot.new @config @bot_class.new bot bot.run end run rescue => e @config.log "Unexpected error", e ensure cleanup end end |