Class: Slacky::Daemon
- Inherits:
-
Object
- Object
- Slacky::Daemon
- Defined in:
- lib/slacky/daemon.rb
Instance Method Summary collapse
- #cleanup ⇒ Object
-
#initialize(config, bot) ⇒ Daemon
constructor
A new instance of Daemon.
- #start(daemonize = true) ⇒ Object
Constructor Details
#initialize(config, bot) ⇒ Daemon
Returns a new instance of Daemon.
4 5 6 7 8 9 |
# File 'lib/slacky/daemon.rb', line 4 def initialize(config, bot) @config = config @bot = bot @active = true @running = false end |
Instance Method Details
#cleanup ⇒ Object
32 33 34 |
# File 'lib/slacky/daemon.rb', line 32 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 |
# 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 @slackthread = Thread.new { @bot.run } run @bot rescue => e @config.log "Unexpected error", e ensure cleanup end end |