Sha256: 733b14844035f41b5c8ae05a2863e374b96ae8986c0c9498727d910c340c135a

Contents?: true

Size: 907 Bytes

Versions: 5

Compression:

Stored size: 907 Bytes

Contents

# frozen_string_literal: true

module Nonnative
  class Process < Runner
    def start
      unless process_exists?
        proxy.start
        @pid = process_spawn
        wait_start
      end

      pid
    end

    def stop
      if process_exists?
        process_kill
        proxy.stop
        wait_stop
      end

      pid
    end

    protected

    def wait_stop
      timeout.perform do
        ::Process.waitpid2(pid)
      end
    end

    private

    attr_reader :pid

    def process_kill
      signal = Signal.list[service.signal || 'INT'] || Signal.list['INT']
      ::Process.kill(signal, pid)
    end

    def process_spawn
      spawn(service.command, %i[out err] => [service.log, 'a'])
    end

    def process_exists?
      return false if pid.nil?

      signal = Signal.list['EXIT']
      ::Process.kill(signal, pid)
      true
    rescue Errno::ESRCH
      false
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
nonnative-1.46.0 lib/nonnative/process.rb
nonnative-1.45.0 lib/nonnative/process.rb
nonnative-1.44.0 lib/nonnative/process.rb
nonnative-1.43.0 lib/nonnative/process.rb
nonnative-1.42.0 lib/nonnative/process.rb