Class to maintain persistent application state
# File lib/openshift-origin-node/utils/application_state.rb, line 41 def initialize(uuid) @uuid = uuid config = OpenShift::Config.new @state_file = File.join(config.get("GEAR_BASE_DIR"), uuid, "app-root", "runtime", ".state") end
Public: Fetch application state from gear.
@return [String] application state or State::UNKNOWN on failure
# File lib/openshift-origin-node/utils/application_state.rb, line 76 def value begin File.open(@state_file) { |input| input.read.chomp } rescue State::UNKNOWN end end
Public: Sets the application state.
@param [String] new_state - From Openshift::State. @return [Object] self for chaining calls
# File lib/openshift-origin-node/utils/application_state.rb, line 52 def value=(new_state) new_state_val = nil begin new_state_val = OpenShift::State.const_get new_state.upcase.intern rescue raise ArgumentError, "Invalid state '#{new_state}' specified" end File.open(@state_file, File::WRONLY|File::TRUNC|File::CREAT, 0640) { |file| file.write "#{new_state_val}\n" } parent = File.dirname(@state_file) OpenShift::Utils.oo_spawn( "chown --reference #{parent} #@state_file; chcon --reference #{parent} #@state_file" ) self end