Class: R2CORBA::INS::Controller
- Inherits:
-
Object
- Object
- R2CORBA::INS::Controller
- Defined in:
- lib/corba/svcs/ins/ins.rb,
lib/corba/svcs/ins/ins.rb,
lib/corba/svcs/ins/ins.rb
Instance Method Summary collapse
-
#initialize(options) ⇒ Controller
constructor
A new instance of Controller.
- #report(msg) ⇒ Object
- #restart ⇒ Object
- #start ⇒ Object
- #status ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(options) ⇒ Controller
Returns a new instance of Controller.
43 44 45 |
# File 'lib/corba/svcs/ins/ins.rb', line 43 def initialize() = end |
Instance Method Details
#report(msg) ⇒ Object
47 48 49 |
# File 'lib/corba/svcs/ins/ins.rb', line 47 def report(msg) STDERR.puts msg if [:verbose] end |
#restart ⇒ Object
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 |
# File 'lib/corba/svcs/ins/ins.rb', line 273 def restart if [:daemon] report 'INS - initializing service' # initialize service ins_svc = INS::Service.new() report 'INS - restarting daemon mode' daemon_opt = { app_name: 'rins', ARGV: ['restart'], dir_mode: :normal, dir: [:piddir], multiple: true, log_dir: [:logdir] || [:piddir], log_output: true, stop_proc: Proc.new do report 'INS - shutting down' ins_svc.shutdown end } Daemons.run_proc('ins.rb', daemon_opt) do report 'INS - daemon started' ins_svc.setup ins_svc.run report 'INS - stopped' end else STDERR.puts 'INS - restart command is only functional in daemon mode' exit 1 end end |
#start ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/corba/svcs/ins/ins.rb', line 54 def start report 'INS - initializing service' if self.pidfile_exists? rc, pid = self.check_pidfile if rc STDERR.puts "ERROR: INS - existing PID file #{self.pidfile} found; service may still be alive" exit 1 else File.delete(self.pidfile) end end begin File.open(self.pidfile, File::CREAT | File::EXCL | File::WRONLY) do |f| f.write Process.pid end report "INS - PID \##{Process.pid} written to '#{self.pidfile}'" rescue ::Exception STDERR.puts "ERROR: INS - failed to write PID file #{self.pidfile}" exit 1 end $ins_service_pid_file = self.pidfile at_exit { File.delete($ins_service_pid_file) } # initialize service ins_svc = INS::Service.new() report 'INS - running service' stop_proc = Proc.new do report 'INS - shutting down' begin; ins_svc.shutdown; rescue ::Exception; STDERR.puts "#{$!}\n#{$!.backtrace.join("\n")}"; end end Signal.trap('INT', stop_proc) Signal.trap('TERM', stop_proc) ins_svc.setup ins_svc.run report 'INS - stopped' end |
#status ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/corba/svcs/ins/ins.rb', line 117 def status report 'INS - retrieving service status' rc, pid = self.check_pidfile if pid if rc STDERR.puts "found PID #{pid} in file #{pidfile} : process is alive" else STDERR.puts "found PID #{pid} in file #{pidfile} : process is not running" exit 1 end end end |
#stop ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/corba/svcs/ins/ins.rb', line 101 def stop report 'INS - stopping service' rc, pid = self.check_pidfile if pid report 'INS - signalling service' if IS_WIN32 Kernel.system("taskkill /PID #{pid} /F") File.delete(self.pidfile) else Process.kill(:TERM, pid) rescue nil end end end |