Class: CPEE::Properties::PutState

Inherits:
Riddl::Implementation
  • Object
show all
Defined in:
lib/cpee/implementation_properties.rb

Overview

}}}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.run(id, opts, state) ⇒ Object



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/cpee/implementation_properties.rb', line 213

def self::run(id,opts,state)
  exe = File.join(opts[:instances],id.to_s,File.basename(opts[:backend_run]))
  case state
    when 'running'
      CPEE::Persistence::write_instance id, opts
      pid = Kernel.spawn(exe , :pgroup => true, :in => '/dev/null', :out => exe + '.out', :err => exe + '.err')
      Process.detach pid
      File.write(exe + '.pid',pid)
    when 'stopping'
      pid = File.read(exe + '.pid') rescue nil
      if pid && (Process.kill(0, pid.to_i) rescue false)
        Process.kill('HUP', pid.to_i) rescue nil
      else
        File.unlink(exe + '.pid') rescue nil
        PutState::set id, opts, 'stopped'
      end
    else
      ### Most probably this is never needed. Lets see.
      PutState::set id, opts, state
  end
end

.set(id, opts, state) ⇒ Object

{{{



209
210
211
# File 'lib/cpee/implementation_properties.rb', line 209

def self::set(id,opts,state)
  CPEE::Persistence::set_item(id,opts,'state',:state => state, :timestamp => Time.now.xmlschema(3))
end

Instance Method Details

#responseObject



235
236
237
238
239
240
241
242
243
244
245
# File 'lib/cpee/implementation_properties.rb', line 235

def response
  id = @a[0]
  opts = @a[1]
  state = @p[0].value
  if opts[:statemachine].setable? id, state
    PutState::run id, opts, state
  else
    @status = 422
  end
  nil
end