Friday Feb 17, 2006

Sun Ray as a Windows Based Terminal using RDesktop

Much to the chagrin of a certain hockey playing CEO and a pony tailed President (not to mention any other long time Sun employee), one of the most popular uses for Sun Ray Thin Clients is to have them display full screen windows desktops using either Citrix or RDP. In this post I'll give an example script or two on how to combine Controlled Access Mode (Kiosk/CAM) with RDesktop to turn the Sun Ray into a Windows Based Terminal. Once you use a Sun Ray as a WBT and compare the ease and flexibility compared to other thin clients, you'll see it's a "wise" choice.

Where to get Rdesktop? If  you're geeky enough, you can compile the source from  Otherwise I'd recommend getting it from,, or the Sun Ray Software Companion CD.

NOTE: Currently Controlled Access Mode is only available on Sun Ray Server installations running on Solaris (SPARC or x86).

Now you can make this real simple, or you can get a little more elaborate.  A simple method can be seen by creating a CAM application to point to a script such as the one in this post.

But let's get a bit more elaborate in this example. 

First a little background.  While Microsoft has support for load balancing in RDP via the Windows Network Load Balancing  Service, there are quite a few short comings.  Brian Madden has an excellent paper on NLB, be sure to read it.  To make up for some of these short comings, you must use the Terminal Server Session Directory.  The big draw back to that is cost since the Session Directory requires that your terminal servers run Windows 2003 Enterprise edition (read 3X the cost of standard Server).  Even with all this, rdesktop does not currently support either as it is missing support for the redirection bit from the terminal server. So for now the point of using either with rdesktop is moot.

This example script will spread out the connections to each Windows terminal server listed.  It is only based on the number of connections to each Windows terminal servers from a single Sun Ray Server, no server load is taken into account so it is really not true load balancing.  However it does a very good job of  making sure each Windows terminal server gets an equal amount of  connections.

Why not just do a simple DNS round robin? Trying to do a typical Round Robin from a multiuser server does not work since each users first request will go to the first entry in DNS Server. This will result in all users going to the first Windows Terminal Server listed, only on that users second request will they be sent to the second WTS.

First we need to ensure that we've enabled Controlled Access Mode when we ran utconfig, then we need to enable CAM for either non-smart card or smart card users or both by changing the Sun Ray Policy.

We will then define a CAM Application.  This CAM application will call our first script which we will call /opt/SUNWutWBT/WBTStart1

The purpose of this script is to check if your terminal servers are reachable (via ping), count the number of connections to each terminal server, then send your Sun Ray to the terminal server with the least number of connections.

# WBTStart1
# Simple Load Balancing Script for RDesktop
# Written by Craig Bender, Sun Ray Engineering
# Enter Your Windows Terminal Servers Below in the WTSARRAY Section
# in a space delimited format as shown below.
# Note that they must match names you connect RDesktop to.
# Hostnames entered must be resolved by a Solaris Naming Service
# (i.e. hosts file or DNS)
# Edit the WTSARRAY line below with the names of your terminal servers
# Server Check and Calculation Area - Do not edit below this line
set -x
for i in `echo $WTSARRAY`
   /usr/sbin/ping $i 2
    if [ $? -eq 0 ]
     echo $i is pingable
      if [ $LBWTSARRAY ]
       export LBWTSARRAY
       export LBWTSARRAY
    else echo $i is not reachable
    echo $i will not be used for load balancing
echo Will check `echo $LBWTSARRAY|awk -F: '{ for (i = NF; i > 0; --i) print $i }'` to see which has the fewest connections.
export LOWEST
for i in `echo $LBWTSARRAY|awk -F: '{ for (i = NF; i > 0; --i) print $i }'`
COUNT=`ps -ef |grep $i|grep -v grep|wc -l`
 if [ $COUNT -lt $LOWEST ] && [ $COUNT -ge 0 ]
  echo $i has $COUNT connections
  echo $i has the same or more connections than other servers
echo Will connect to $WTS that has $LOWEST connections
/opt/SUNWutWBT/WBTStart2 $WTS
# End of Script

Now we need to create the second script, which we will call /opt/SUNWutWBT/WBTStart2.  The only reason why we have this going into a separate script is so that we can properly count the number of times a Windows Terminal Server is being called.  If we just embedded the rdestkop command into this script, the ps utility would truncate the name of the Windows Terminal Server since RDesktop expects the terminal server to connect to as the last argument.  This would cause our counting method to fail.

Feel free to add other options as supported by RDesktop to this script, including disk mapping, printer redirection, serial port mapping, etc.

# WBTStart2
# Written by Craig Bender, Sun Ray Engineering

# Fix alt+printscreen for older versions of rdesktop
/usr/openwin/bin/xmodmap -e 'keycode 77 = 0xff61'
# Turn numlock on
/usr/openwin/bin/xset led 1
# Launch rdesktop
/opt/SUNWrdp/bin/rdesktop -f -a 24 -r sound -u "" $1

Now all we need to do is configure CAM to Start Rdesktop

1. Open Sun Ray Administration Web Page and login
    a. http://localhost:1660
2. Click Controlled Access Mode
3. Click Add/Edit Applications
4. Enter SUNWutWBT for Application Name
5. Enter SUNWutWBT for Application Menu Label
6. Enter /opt/SUNWutWBT/WBTStart1 for the Path of Application
    a. Select an attribute. Select default to test, then move to Critical once you know everything works.
7. Click Add New
8. Click Select Applications
9. Click SUNWutWBT, click the Add>> button
10. Click Confirm, click Confirm Settings

Finally we need to choose a policy for CAM to operate under

1. Click Admin from the Sun Ray Administration Web page
2. Click Policy
3. Ensure that your policy reflects your use of smart cards
4. Ensure that Controlled Access Mode is selected
5. Click Restart Services
6. Choose group or local depending on your failover group setup
7. Choose Restart


All Sun Rays should now come up as a Windows Based Terminal using Rdesktop depending on your policy.

Think Thin is a collection of bloggers that work with Oracle's Virtual Desktop portfolio of products.


« July 2016