Sha256: 5b861f976dfb610bb062f3799713a6d214bc167d9622eae1127f85d9cbb43ad3

Contents?: true

Size: 1.38 KB

Versions: 7

Compression:

Stored size: 1.38 KB

Contents

module Nephos

  module Bin

    # @param dir [String]
    #
    # The method check in the parameter directory:
    # - if the directory exists
    # - if a Gemfile.lock has been generated
    # - if it contain nephos-server dependency
    #
    # note: if the Gemfile includes nephos and not nephos-server,
    # it will work anyway, because nephos require nephos-server
    def self.is_a_valid_application? dir="."
      return false if not Dir.exists? dir
      gfl = File.expand_path "Gemfile.lock", dir
      return false if not File.exists? gfl
      return false if not File.read(gfl).split.index("nephos-server")
      return true
    end

    module Daemon

      def self.started?
        get_pid != nil
      end

      def self.kill!
        d = get_pid
        return false unless d
        begin
          Process::kill(10, d)
        rescue => err
          raise "Cannot kill #{d} !"
        ensure
          File.delete(get_pid_file)
        end
        return true
      end

      def self.detach!
        Process::daemon(true, false)
        File.write(get_pid_file, Process::pid.to_s)
      end

      def self.get_pid_file
        return ".pid"
      end

      def self.get_pid
        return nil if not File.exists?(get_pid_file)
        v = File.read(get_pid_file)
        v = Integer(v) rescue nil
        return v
      end

    end

  end

end

class BinError < StandardError; end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
nephos-server-0.6.8 lib/nephos-server/bin-helpers.rb
nephos-server-0.6.7 lib/nephos-server/bin-helpers.rb
nephos-server-0.6.5 lib/nephos-server/bin-helpers.rb
nephos-server-0.6.4 lib/nephos-server/bin-helpers.rb
nephos-server-0.6.3 lib/nephos-server/bin-helpers.rb
nephos-server-0.6.2 lib/nephos-server/bin-helpers.rb
nephos-server-0.6.1 lib/nephos-server/bin-helpers.rb