Skip to content

Instantly share code, notes, and snippets.

@artemave
Created June 3, 2011 10:16
Show Gist options
  • Save artemave/1006135 to your computer and use it in GitHub Desktop.
Save artemave/1006135 to your computer and use it in GitHub Desktop.
setup vnc server for any subsequent process (like cucumber -> firefox) to use vnc display
def _vnc_setup
d = '22' # vnc desktop number
ENV['DISPLAY'] = "localhost:#{d}"
hostname = `hostname`.chomp
vnc_pid_file = File.join(ENV['HOME'], ".vnc", "#{hostname}:#{d}.pid")
if File.exist?(vnc_pid_file)
pid = File.open(vnc_pid_file).read.chomp
log "Xvnc appears to be already running with pid #{pid}"
if `/bin/ps -p #{pid}`.split.last =~ /Xvnc/
return
else
log "old pid file found #{vnc_pid_file} . killing and removing.."
log "vncserver -kill :#{d}"
log `vncserver -kill :#{d}`
log "rm #{vnc_pid_file}"
log `rm #{vnc_pid_file}`
end
else
log "vnc pid file not found #{vnc_pid_file}"
end
log "starting new vncserver"
log "vncserver -geometry 1200x1200 -depth 24 :#{d}"
fork do
daemonize
`vnc4server -geometry 1200x1200 -depth 24 :#{d}`
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment