Module: CPEE::Instantiation
- Defined in:
- lib/cpee-instantiation/utils.rb,
lib/cpee-instantiation/instantiation.rb
Defined Under Namespace
Modules: Helpers Classes: ContinueTask, HandleInstance, InstantiateGit, InstantiateUrl, InstantiateXML
Constant Summary collapse
- SERVER =
File.(File.join(__dir__,'instantiation.xml'))
Class Method Summary collapse
- .cleanup_services(watchdog_start_off) ⇒ Object
-
.implementation(opts) ⇒ Object
}}}.
- .watch_services(watchdog_start_off, url, path, db) ⇒ Object
Class Method Details
.cleanup_services(watchdog_start_off) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/cpee-instantiation/utils.rb', line 39 def self::cleanup_services(watchdog_start_off) return if watchdog_start_off Dir[File.join(__dir__,'routing','*.rb')].each do |s| s = s.sub(/\.rb$/,'') pid = (File.read(s + '.pid').to_i rescue nil) if !pid.nil? || (Process.kill(0, pid) rescue false) system "#{s}.rb stop 1>/dev/null 2>&1" puts "➡ Service #{File.basename(s,'.rb')} stopped ..." end end end |
.implementation(opts) ⇒ Object
}}}
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 |
# File 'lib/cpee-instantiation/instantiation.rb', line 417 def self::implementation(opts) opts[:cpee] ||= 'http://localhost:9298/' opts[:self] ||= "http#{opts[:secure] ? 's' : ''}://#{opts[:host]}:#{opts[:port]}/" opts[:watchdog_frequency] ||= 7 opts[:watchdog_start_off] ||= false ### set redis_cmd to nil if you want to do global ### at least redis_path or redis_url and redis_db have to be set if you do global opts[:redis_path] ||= 'redis.sock' # use e.g. /tmp/redis.sock for global stuff. Look it up in your redis config opts[:redis_db] ||= 0 ### optional redis stuff opts[:redis_url] ||= nil opts[:redis_cmd] ||= 'redis-server --port 0 --unixsocket #redis_path# --unixsocketperm 600 --pidfile #redis_pid# --dir #redis_db_dir# --dbfilename #redis_db_name# --databases 1 --save 900 1 --save 300 10 --save 60 10000 --rdbcompression yes --daemonize yes' opts[:redis_pid] ||= 'redis.pid' # use e.g. /var/run/redis.pid if you do global. Look it up in your redis config opts[:redis_db_name] ||= 'redis.rdb' # use e.g. /var/lib/redis.rdb for global stuff. Look it up in your redis config CPEE::redis_connect opts, 'Instantiation' Proc.new do parallel do CPEE::Instantiation::watch_services(opts[:watchdog_start_off],opts[:redis_url],File.join(opts[:basepath],opts[:redis_path]),opts[:redis_db]) EM.add_periodic_timer(opts[:watchdog_frequency]) do ### start services CPEE::Instantiation::watch_services(opts[:watchdog_start_off],opts[:redis_url],File.join(opts[:basepath],opts[:redis_path]),opts[:redis_db]) end end on resource do run InstantiateXML, opts[:cpee], true if post 'xmlsimple' on resource 'xml' do run InstantiateXML, opts[:cpee], false if post 'xml' end on resource 'url' do run InstantiateUrl, opts[:cpee], opts[:self], opts[:redis], false if post 'url' run InstantiateUrl, opts[:cpee], opts[:self], opts[:redis], true if post 'url_info' end on resource 'git' do run InstantiateGit, opts[:cpee], opts[:self], opts[:redis] if post 'git' end on resource 'instance' do run HandleInstance, opts[:cpee], opts[:self], opts[:redis] if post 'instance' end on resource 'callback' do on resource do run ContinueTask, opts[:cpee], opts[:redis] if post end end end end end |
.watch_services(watchdog_start_off, url, path, db) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/cpee-instantiation/utils.rb', line 20 def self::watch_services(watchdog_start_off,url,path,db) return if watchdog_start_off EM.defer do Dir[File.join(__dir__,'routing','*.rb')].each do |s| s = s.sub(/\.rb$/,'') pid = (File.read(s + '.pid').to_i rescue nil) cmd = if url.nil? "-p \"#{path}\" -d #{db} restart" else "-u \"#{url}\" -d #{db} restart" end if (pid.nil? || !(Process.kill(0, pid) rescue false)) && !File.exist?(s + '.lock') system "#{s}.rb " + cmd + " 1>/dev/null 2>&1" puts "➡ Service #{File.basename(s)} (-v #{cmd}) started ..." end end end end |