Did you know ... | Search Documentation: |
Running the server under VNC (Unix) |
A nice way to deploy the SWI-Prolog based servers is by using
VNC. We
refer to the Wikipedia page because there are various implementations of
VNC around. We use TightVNC, but the others will probably work fine as
well. VNC is a virtual desktop to which you can connect using a thin
client called vncviewer
. Starting the server is automatically done
in two steps:
service(s)
run.
The nice part is that you can connect to the server using vncviewer
,
and access the Prolog toplevel to reload or debug the server. You can
even run the graphical debugger, although tracing will be complicated
on a heavily loaded server.
Unfortunately, the setup requires root privileges and some Unix skills.
Below, we outline the steps for Debian and Debian derived systems (e.g.,
Ubuntu). This can serve as a starting point for all Unix-based systems.
We assume TightVNC, root privileges and these steps create a user
wwwswi
.
% sudo apt-get install tightvncserver xtightvncviewer
useradd
. E.g.
% sudo useradd -c "SWI-Prolog HTTP servers" -m -r -s /bin/bash wwwswi
% sudo -iu wwwswi bash $ unset XAUTHORITY $ vncserver You will require a password to access your desktops. Password: Verify: Would you like to enter a view-only password (y/n)? n ... New 'X' desktop is ct:1
The unset XAUTHORITY
is not really needed, but avoids a long
timeout trying to establish X11 authorization with the original
user.
1
is the display returned by New 'X' desktop is ct:1
% vncviewer <host>:1
Verify security and access restrictions. VNC uses port 5900+display. Login verification is challenge-response based, but further communication is not encrypted. There are many ways to improve that, e.g., by using tunneling over SSH.
Since a long time, the default Gnome
desktop in VNC has an annoying bug: typing a d closes all
windows. Open "System/Preferences/Keyboard shortcuts" and disable or
change the shortcut. I needed to stop and restart the server.
Stopping can be done from the shell in (3) using vncserver -kill
:1
% git clone git://www.swi-prolog.org/home/pl/git/ClioPatria.git % mkdir test % cd test % ../ClioPatria/configure
Optionally, you may wish to add a run
script to restart the server
in the case that it crashes. E.g.
#!/bin/bash cd $HOME/test while true; do ./run.pl sleep 1 done
gnome-terminal -t "Demo Server" -e $HOME/test/run
You can now test the restart by going to the shell you created in (3) and running these commands to stop and start the server. You may need to adjust the display in the first command.
% vncserver -kill :1 % vncserver
If everything works fine, the server nicely restarts and you can
access it from your browser (ClioPatria runs on port 3020 by
default, so the address is http://localhost:3020). You can also
contact the desktop using vcnviewer
to type commands in the
Prolog window.
lsvnc
for that. Here is the content:
#!/bin/sh ps aux | \ grep Xtightvnc | \ grep ' :[0-9][0-9]* ' | \ sed 's/\(^[a-z][a-z]*\).* \(:[0-9][0-9]*\) .*/\1 \2/g'
Using this, we can verify that the server is running using this bash fragment:
check() { /usr/local/bin/lsvnc | grep -qw $VNCUSER }
rm -f /tmp/.X11-unix/X$VNC_DISPLAY su $VNCUSER -c "cd /home/$VNCUSER && bin/server :$VNC_DISPLAY"
su $VNC_USER -c "vncserver -kill :$VNC_DISPLAY"