Skip to content

Instantly share code, notes, and snippets.

@ayosec
Created July 17, 2012 13:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ayosec/3129293 to your computer and use it in GitHub Desktop.
Save ayosec/3129293 to your computer and use it in GitHub Desktop.
Scripts to start a Xvnc server inside a machine

Xvnc

The scripts in this gist will start an Xvnc server with a basic window manager (IceWM). This is intended to use in a virtual machine, where we can need to start a browser to run a test suite.

Installation on Debian

All commands have to be run as root

apt-get install icewm vnc4server
wget -O /etc/init.d/xvnc https://raw.github.com/gist/3129293/5342e9e1705041939aa3e3e417de09c3d16131b1/xvnc.sh
wget -O /etc/init.d/icewm https://raw.github.com/gist/3129293/b6ab30fb47dfdd5d4eccd64c540f1424db13b8d7/icewm.sh
chmod +x /etc/init.d/xvnc /etc/init.d/icewm
update-rc.d xvnc defaults
update-rc.d icewm defaults

Then, in your user, type

echo 'export DISPLAY=:0' >> ~/.bashrc
#!/bin/sh
### BEGIN INIT INFO
# Provides: icewm
# Required-Start: xvnc
# Required-Stop: xvnc
# Should-Start: icewm
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Ice Window Manager
### END INIT INFO
PID_FILE=/run/icewm.pid
export DISPLAY=:0
cmd() {
action="--$1"
shift
start-stop-daemon $action \
--pidfile $PID_FILE \
--exec /usr/bin/icewm \
--name icewm \
--chuid 1000 \
--make-pidfile \
"$@"
}
case "$1" in
start)
cmd start --background
;;
stop)
cmd stop
;;
status)
cmd status
;;
*)
echo "Unknown option $1"
;;
esac
#!/bin/sh
### BEGIN INIT INFO
# Provides: xvnc
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Should-Start: xvnc
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Xvnc
### END INIT INFO
PID_FILE=/run/Xvnc.pid
cmd() {
action="--$1"
shift
start-stop-daemon $action \
--pidfile $PID_FILE \
--exec /usr/bin/Xvnc \
--name Xvnc \
--chuid 1000 \
--make-pidfile \
"$@"
}
case "$1" in
start)
cmd start --background -- :0 -geometry 1440x900 -SecurityTypes None
;;
stop)
cmd stop
;;
status)
cmd status
;;
*)
echo "Unknown option $1"
;;
esac
@estebanm
Copy link

I think you're missing an "export" in the "DISPLAY=:0" in icewm.sh...

Otherwise, good stuff, thanks a lot! I was having problems setting up a headless server myself, this seemed to work (I have no idea what exactly is different from my attempts...).

@ayosec
Copy link
Author

ayosec commented Jul 18, 2012

Thanks for the comment!

It was working without the export. Maybe it will fail if it starts more processes behind the IceWM. I've added it to the gist. =)

We are using Linux Containers for our development. These scripts are used to be able to run Selenium with Firefox.

@emanchado
Copy link

Ah, and I forgot to say that the PID file path is the same for both scripts :-)

@ayosec
Copy link
Author

ayosec commented Jul 18, 2012

Ouch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment