class StickShift::ApplicationContainer

Application Container

Attributes

application_uuid[R]
user[R]
uuid[R]

Public Class Methods

new(application_uuid, container_uuid, user_uid = nil, app_name = nil, container_name = nil, namespace = nil, quota_blocks = nil, quota_files = nil) click to toggle source
# File lib/stickshift-node/model/application_container.rb, line 29
def initialize(application_uuid, container_uuid, user_uid = nil,
    app_name = nil, container_name = nil, namespace = nil, quota_blocks = nil, quota_files = nil)
  @config = StickShift::Config.instance

  @uuid = container_uuid
  @application_uuid = application_uuid
  @user = UnixUser.new(application_uuid, container_uuid, user_uid,
    app_name, container_name, namespace, quota_blocks, quota_files)
end

Public Instance Methods

create() click to toggle source

Create gear - model/unix_user.rb

# File lib/stickshift-node/model/application_container.rb, line 44
def create
  notify_observers(:before_container_create)
  @user.create
  notify_observers(:after_container_create)
end
destroy(skip_hooks=false) click to toggle source

Destroy gear - model/unix_user.rb

# File lib/stickshift-node/model/application_container.rb, line 51
def destroy(skip_hooks=false)
  notify_observers(:before_container_destroy)

  hook_timeout=30

  output = ""
  errout = ""
  retcode = 0

  hooks={}
  ["pre", "post"].each do |hooktype|
    if @user.homedir.nil?
      hooks[hooktype]=[]
    else
      hooks[hooktype] = Dir.entries(@user.homedir).map { |cart|
        [ File.join(@config.get("CARTRIDGE_BASE_PATH"),cart,"info","hooks","#{hooktype}-destroy"),
          File.join(@config.get("CARTRIDGE_BASE_PATH"),"embedded",cart,"info","hooks","#{hooktype}-destroy"),
        ].select { |hook| File.exists? hook }[0]
      }.select { |hook|
        not hook.nil?
      }.map { |hook|
        "#{hook} #{@user.container_name} #{@user.namespace} #{@user.container_uuid}"
      }
    end
  end

  unless skip_hooks
    hooks["pre"].each do | cmd |
      out,err,rc = shellCmd(cmd, "/", true, 0, hook_timeout)
      errout << err if not err.nil?
      output << out if not out.nil?
      retcode = 121 if rc != 0
    end
  end

  @user.destroy

  unless skip_hooks
    hooks["post"].each do | cmd |
      out,err,rc = shellCmd(cmd, "/", true, 0, hook_timeout)
      errout << err if not err.nil?
      output << out if not out.nil?
      retcode = 121 if rc != 0
    end
  end

  notify_observers(:after_container_destroy)

  return output, errout, retcode
end
get_app_state() click to toggle source

Public: Fetch application state from gear. Returns app state as string on Success and 'unknown' on Failure

# File lib/stickshift-node/model/application_container.rb, line 104
def get_app_state
  env = load_env
  app_state_file=File.join(env[:OPENSHIFT_HOMEDIR], 'app-root', 'runtime', '.state')
  
  if File.exists?(app_state_file)
    app_state = nil
    File.open(app_state_file) { |input| app_state = input.read.chomp }
  else
    app_state = 'unknown'
  end
  app_state
end
load_env() click to toggle source

Public: Load a gears environment variables into the environment

Examples

load_env
# => {"OPENSHIFT_GEAR_DIR"=>"/var/lib/UUID/mysql-5.3",
      "OPENSHIFT_APP_NAME"=>"myapp"}

Returns env Array

# File lib/stickshift-node/model/application_container.rb, line 126
def load_env
  env = {}
  # Load environment variables into a hash
  
  Dir["#{user.homedir}/.env/*"].each { | f |
    next if File.directory?(f)
    contents = nil
    File.open(f) {|input|
      contents = input.read.chomp
      index = contents.index('=')
      contents = contents[(index + 1)..-1]
      contents = contents[%r'(.*)'/, 1] if contents.start_with?("'")
      contents = contents[%r"(.*)"/, 1] if contents.start_with?('"')
    }
    env[File.basename(f).intern] =  contents
  }
  env
end
name() click to toggle source
# File lib/stickshift-node/model/application_container.rb, line 39
def name
  @uuid
end