Module: Documentalist::OpenOffice::Server
- Defined in:
- lib/backends/open_office.rb
Class Method Summary collapse
-
.ensure_available ⇒ Object
Make sure there will be an available instance.
-
.kill! ⇒ Object
Kill running instance.
-
.pids ⇒ Object
Get OO processes pids.
-
.restart! ⇒ Object
Restart if running or start new instance.
-
.running? ⇒ Boolean
Is OpenOffice server running?.
-
.stalled? ⇒ Boolean
Is the current instance stuck ?.
-
.start! ⇒ Object
Start new instance.
Class Method Details
.ensure_available ⇒ Object
Make sure there will be an available instance
118 119 120 121 |
# File 'lib/backends/open_office.rb', line 118 def self.ensure_available start! unless running? restart! if stalled? end |
.kill! ⇒ Object
Kill running instance
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/backends/open_office.rb', line 92 def self.kill! raise "Not running!" unless running? begin Documentalist.timeout(3) do while(running?) system("pkill -9 office") end end rescue Timeout::Error raise "Mayday, mayday ! Could not kill OpenOffice !!" ensure # Remove user profile system("rm -rf ~/openoffice.org*") end end |
.pids ⇒ Object
Get OO processes pids
124 125 126 |
# File 'lib/backends/open_office.rb', line 124 def self.pids `pgrep soffice`.split.map(&:to_i) unless `pgrep soffice`.empty? end |
.restart! ⇒ Object
Restart if running or start new instance
59 60 61 62 63 |
# File 'lib/backends/open_office.rb', line 59 def self.restart! Documentalist.logger.debug("Restarting OpenOffice instance...") (kill! if running?) and start! Documentalist.logger.debug("...done !") end |
.running? ⇒ Boolean
Is OpenOffice server running?
54 55 56 |
# File 'lib/backends/open_office.rb', line 54 def self.running? !`pgrep soffice`.empty? end |
.stalled? ⇒ Boolean
Is the current instance stuck ?
110 111 112 113 114 115 |
# File 'lib/backends/open_office.rb', line 110 def self.stalled? if running? cpu_usage = `ps -Ao pcpu,pid,comm | grep soffice | grep [#{pids.collect{|pid| '\('+pid.to_s+'\)'}}]`.split(/\n/) cpu_usage.any? { |usage| /^\s*\d+/.match(usage)[0].strip.to_i > Documentalist.config[:open_office][:max_cpu] } end end |
.start! ⇒ Object
Start new instance
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/backends/open_office.rb', line 66 def self.start! Documentalist.logger.debug("Starting OpenOffice instance...") raise "Already running!" if running? command_line = "#{Documentalist.config[:open_office][:path]} -headless -accept=\"socket,host=127.0.0.1,port=8100\;urp\;\" -nofirststartwizard -nologo -nocrashreport -norestore -nolockcheck -nodefault" command_line << " >> #{Documentalist.config[:log_file]} 2>&1" command_line << " &" system(command_line) begin Documentalist.timeout(Documentalist.config[:open_office][:max_startup_time]) do while !running? # Do nothing end end rescue Timeout::Error raise "OpenOffice didn't start fast enough, you might want to increase the max_startup_time value or check your OpenOffice configuration" end # OpenOffice needs some time to fully wake up sleep(Documentalist.config[:open_office][:wakeup_time]) nil end |