Sha256: a97f0be357f2ee385e2f3f4378cf46f6aa3b2a538197973c5275c5408409315c

Contents?: true

Size: 880 Bytes

Versions: 3

Compression:

Stored size: 880 Bytes

Contents

class Application
  include DataMapper::Resource

  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 = Servant.watch(cmd){
      stopped
    }
    self.save
  end

  def stop
    if self.pid
      Servant.kill(self.pid)
      stopped
    end
  end

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

  private

  def stopped
    self.pid = nil
    self.save
  end

  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 & 1 rubygems

Version Path
ruby-station-0.1.2 model/application.rb
ruby-station-0.1.1 model/application.rb
ruby-station-0.1.0 model/application.rb