Sha256: 8935cbfb38be0916ca9e650ddcf4bd4bad7ec0f92ec88e71ae2a05d2b6031a86

Contents?: true

Size: 1.48 KB

Versions: 15

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

      # Terminates the process gracefully
      def init_int_signal
        trap :INT do
          puts 'Exiting process gracefully!'
          stop
        end
      end

      # Terminates the process gracefully
      def init_term_signal
        trap :TERM do
          puts 'Exiting process gracefully!'
          stop
        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

15 entries across 15 versions & 1 rubygems

Version Path
process_handler-4.1.0 lib/salemove/process_handler/process_monitor.rb
process_handler-4.0.0 lib/salemove/process_handler/process_monitor.rb
process_handler-3.0.0 lib/salemove/process_handler/process_monitor.rb
process_handler-2.3.0 lib/salemove/process_handler/process_monitor.rb
process_handler-2.2.0 lib/salemove/process_handler/process_monitor.rb
process_handler-2.1.0 lib/salemove/process_handler/process_monitor.rb
process_handler-2.0.0 lib/salemove/process_handler/process_monitor.rb
process_handler-1.1.2 lib/salemove/process_handler/process_monitor.rb
process_handler-1.1.1 lib/salemove/process_handler/process_monitor.rb
process_handler-1.1.0 lib/salemove/process_handler/process_monitor.rb
process_handler-1.0.0 lib/salemove/process_handler/process_monitor.rb
process_handler-0.3.0 lib/salemove/process_handler/process_monitor.rb
process_handler-0.2.9 lib/salemove/process_handler/process_monitor.rb
process_handler-0.2.8 lib/salemove/process_handler/process_monitor.rb
process_handler-0.2.7 lib/salemove/process_handler/process_monitor.rb