mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-22 18:50:08 +03:00
feature #1370: make novnc-server run in ruby 1.8.7
This commit is contained in:
parent
7ac5896a90
commit
154e871aac
@ -18,6 +18,7 @@
|
||||
# This class provides support for launching and stopping a websockify proxy
|
||||
#
|
||||
|
||||
require 'rubygems'
|
||||
require 'json'
|
||||
require 'opennebula'
|
||||
|
||||
@ -81,13 +82,15 @@ class OpenNebulaVNC
|
||||
|
||||
begin
|
||||
@logger.info { "Starting VNC proxy: #{cmd}" }
|
||||
pid=start_daemon(cmd, 'VNC_LOG')
|
||||
pid=start_daemon(cmd, VNC_LOG)
|
||||
rescue Exception => e
|
||||
@logger.error e.message
|
||||
return false
|
||||
end
|
||||
|
||||
File.write(@lock_file, pid)
|
||||
File.open(@lock_file, "w") do |f|
|
||||
f.write(pid.to_s)
|
||||
end
|
||||
|
||||
sleep 1
|
||||
|
||||
@ -242,12 +245,33 @@ class OpenNebulaVNC
|
||||
end
|
||||
alias_method :get_pid, :is_running?
|
||||
|
||||
if RUBY_VERSION<'1.9'
|
||||
def spawn(*args)
|
||||
fork {
|
||||
command=args[0..-2]
|
||||
|
||||
# Close stdin and point out and err to log file
|
||||
$stdin.close
|
||||
$stdout.reopen(VNC_LOG, "a")
|
||||
$stderr.reopen(VNC_LOG, "a")
|
||||
|
||||
# Detach process from the parent
|
||||
Process.setsid
|
||||
|
||||
exec(*command)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def start_daemon(cmd, log)
|
||||
pid=spawn(*cmd.split(" "),
|
||||
options={
|
||||
:pgroup => true,
|
||||
:in => :close,
|
||||
[:out, :err] => [log, "a"],
|
||||
:close_others => true )
|
||||
:close_others => true }
|
||||
|
||||
params=cmd.split(" ")+[options]
|
||||
pid=spawn( *params )
|
||||
|
||||
Process.detach(pid)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user