Sha256: 049219fd6858adaa7bc317d8caa5143675fb89d5168ee7d0965971bc1ddf46a8

Contents?: true

Size: 1.48 KB

Versions: 11

Compression:

Stored size: 1.48 KB

Contents

module Salemove
  module ProcessHandler
    class ProcessMonitor
      def start
        init_signal_handlers
        @state = :running
      end

      def stop
        @state = :stopping if alive?
      end

      def shutdown
        @state = :stopped
      end

      def running?
        @state == :running
      end

      def alive?
        @state != :stopped
      end

      private

      def init_signal_handlers
        init_hup_signal
        init_quit_signal
        init_int_signal
        init_term_signal
      end

      # Many daemons will reload their configuration files and reopen their
      # logfiles instead of exiting when receiving this signal.
      def init_hup_signal
        trap :HUP do
          puts 'SIGHUP: not implemented'
        end
      end

      # Interrupts a process. (The default action is to terminate gracefully).
      def init_int_signal
        trap :INT do
          puts 'Exiting process gracefully!'
          stop
        end
      end

      # Terminates a process immediately.
      def init_term_signal
        trap :TERM do
          exit
        end
      end

      # Terminates a process. This is different from both SIGKILL and SIGTERM
      # in the sense that it generates a core dump of the process and also
      # cleans up resources held up by a process. Like SIGINT, this can also
      # be sent from the terminal as input characters.
      def init_quit_signal
        trap :QUIT do
          exit
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
process_handler-0.2.5 lib/salemove/process_handler/process_monitor.rb
process_handler-0.2.4 lib/salemove/process_handler/process_monitor.rb
process_handler-0.2.3 lib/salemove/process_handler/process_monitor.rb
process_handler-0.2.2 lib/salemove/process_handler/process_monitor.rb
process_handler-0.2.1 lib/salemove/process_handler/process_monitor.rb
process_handler-0.2.0 lib/salemove/process_handler/process_monitor.rb
process_handler-0.1.5 lib/salemove/process_handler/process_monitor.rb
process_handler-0.1.4 lib/salemove/process_handler/process_monitor.rb
process_handler-0.1.3 lib/salemove/process_handler/process_monitor.rb
process_handler-0.1.1 lib/salemove/process_handler/process_monitor.rb
process_handler-0.1.0 lib/salemove/process_handler/process_monitor.rb