Sha256: e92ba949f8a3a3ad6b1b0acf8870d38bcc1666a2df0b190635400cdb248e18fc

Contents?: true

Size: 1.04 KB

Versions: 3

Compression:

Stored size: 1.04 KB

Contents

require 'ramaze/tool/bin'

class Application
  include DataMapper::Resource
  include Ramaze::Tool::Bin::Helpers

  property :id, Serial
  property :pid, Integer
  property :port, Integer
  property :name, String
  property :version, String

  def start
    return if self.pid

    cmd = [
      Conf.ruby_command,
      script_path,
      "--port", self.port.to_s,
      "--data-dir", data_dir,
    ].join(" ")

    self.pid = fork {
      exec(cmd)
    }
    self.save
  end

  def stop
    return unless self.pid

    Process.kill("INT", self.pid)
    if is_running?(self.pid)
      sleep 2
      Ramaze::Log.warn "Process #{self.pid} did not die, forcing it with -9"
      Process.kill(9, self.pid)
    end

    self.pid = nil
    self.save
  end

  def full_name
    "#{self.name}-#{self.version}"
  end

  private

  def script_path
    File.join(Conf.gem_dir, "gems",
              full_name, "main.rb")
  end

  def data_dir
    File.join(Conf.data_dir, full_name)
  end
end
DataMapper.auto_upgrade!

Application.all.each{|a| a.update_attributes(:pid => nil)}

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
yhara-ruby-station-0.0.1 model/application.rb
yhara-ruby-station-0.0.2 model/application.rb
ruby-station-0.0.4 model/application.rb