Tips – xRDP Custom Installation Possible Issues and Solutions

XRDP_Issues

Hello World,

Back again on the topic xrdp on Ubuntu 15.04.  In one of our previous posts, we have demonstrated how to perform a custom installation of xRDP.   Some of my colleagues have also performed  a custom xRDP installation and they came back to me with two minor issues as they do not prevent you to use xRDP software.

Issue 1 – xrdp service status marked as Failed

In general, in order to check that the xrdp service is running properly, a user would issue the following command in the Terminal console

sudo service xrdp status

My colleagues have noticed that when running this command after having performed a custom installation, the expected result is not return. Instead, you will see a clear fail error message displayed

 Click on Picture for better resolution

The fix is quite easy actually.  We need to update the /etc/init.d/xrdp to reflect the fact that we have performed a custom installation.  Make a copy of your /etc/init.d/xrdp and then update the /etc/init.d/xrdp file with the information  below

<-------   Begin of the Script -------->
#!/bin/sh -e
#
# start/stop xrdp and sesman daemons
#
### BEGIN INIT INFO
# Provides:          xrdp
# Required-Start:    $network $remote_fs
# Required-Stop:     $network $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start xrdp and sesman daemons
# Description:       XRDP uses the Remote Desktop Protocol to present a
#                    graphical login to a remote client allowing connection
#                    to a VNC server or another RDP server.
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/sbin/xrdp
PIDDIR=/var/run
SESMAN_START=yes
USERID=xrdp
RSAKEYS=/etc/xrdp/rsakeys.ini
NAME=xrdp
DESC="Remote Desktop Protocol server"

test -x $DAEMON || exit 0

. /lib/lsb/init-functions

check_root()  {
    if [ "$(id -u)" != "0" ]; then
        log_failure_msg "You must be root to start, stop or restart $NAME."
        exit 4
    fi
}

if [ -r /etc/default/$NAME ]; then
   . /etc/default/$NAME
fi

# Tasks that can only be run as root
if [ "$(id -u)" = "0" ]; then
    # Check for pid dir
    if [ ! -d $PIDDIR ] ; then
        mkdir $PIDDIR
    fi
    chown $USERID:$USERID $PIDDIR

    # Check for rsa key 
    if [ ! -f $RSAKEYS ] || cmp $RSAKEYS /usr/share/doc/xrdp/rsakeys.ini > /dev/null; then
        log_action_begin_msg "Generating xrdp RSA keys..."
        (umask 077 ; xrdp-keygen xrdp $RSAKEYS)
        chown $USERID:$USERID $RSAKEYS
        if [ ! -f $RSAKEYS ] ; then
            log_action_end_msg 1 "could not create $RSAKEYS"
            exit 1
        fi
        log_action_end_msg 0 "done"
    fi
fi

case "$1" in
  start)
        check_root
        exitval=0
        log_daemon_msg "Starting $DESC " 
        if pidofproc -p $PIDDIR/$NAME.pid $DAEMON > /dev/null; then
            log_progress_msg "$NAME apparently already running"
            log_end_msg 0
            exit 0
        fi
        log_progress_msg $NAME
        start-stop-daemon --start --quiet --oknodo  --pidfile $PIDDIR/$NAME.pid \
	    --chuid $USERID:$USERID --exec $DAEMON
        exitval=$?
	if [ "$SESMAN_START" = "yes" ] ; then
            log_progress_msg "sesman"
            start-stop-daemon --start --quiet --oknodo --pidfile $PIDDIR/xrdp-sesman.pid \
	       --exec /usr/local/sbin/xrdp-sesman
            value=$?
            [ $value -gt 0 ] && exitval=$value
        fi
        # Make pidfile readables for all users (for status to work)
        [ -e $PIDDIR/xrdp-sesman.pid ] && chmod 0644 $PIDDIR/xrdp-sesman.pid
        [ -e $PIDDIR/$NAME.pid ] && chmod 0644 $PIDDIR/$NAME.pid
        # Note: Unfortunately, xrdp currently takes too long to create
        # the pidffile unless properly patched
        log_end_msg $exitval
	;;
  stop)
        check_root
	[ -n "$XRDP_UPGRADE" -a "$RESTART_ON_UPGRADE" = "no" ] && {
	    echo "Upgrade in progress, no restart of xrdp."
	    exit 0
	}
        exitval=0
        log_daemon_msg "Stopping RDP Session manager " 
        log_progress_msg "sesman"
        if pidofproc -p  $PIDDIR/xrdp-sesman.pid /usr/local/sbin/xrdp-sesman  > /dev/null; then
            start-stop-daemon --stop --quiet --oknodo --pidfile $PIDDIR/xrdp-sesman.pid \
                --chuid $USERID:$USERID --exec /usr/local/sbin/xrdp-sesman
            exitval=$?
        else
            log_progress_msg "apparently not running"
        fi
        log_progress_msg $NAME
        if pidofproc -p  $PIDDIR/$NAME.pid $DAEMON  > /dev/null; then
            start-stop-daemon --stop --quiet --oknodo --pidfile $PIDDIR/$NAME.pid \
	    --exec $DAEMON
            value=$?
            [ $value -gt 0 ] && exitval=$value
        else
            log_progress_msg "apparently not running"
        fi
        log_end_msg $exitval
	;;
  restart|force-reload)
        check_root
	$0 stop
        # Wait for things to settle down
        sleep 1
	$0 start
	;;
  reload)
        log_warning_msg "Reloading $NAME daemon: not implemented, as the daemon"
        log_warning_msg "cannot re-read the config file (use restart)."
        ;;
  status)
        exitval=0
        log_daemon_msg "Checking status of $DESC" "$NAME"
        if pidofproc -p  $PIDDIR/$NAME.pid $DAEMON  > /dev/null; then
            log_progress_msg "running"
            log_end_msg 0
        else
            log_progress_msg "apparently not running"
            log_end_msg 1 || true
            exitval=1
        fi
	if [ "$SESMAN_START" = "yes" ] ; then
            log_daemon_msg "Checking status of RDP Session Manager" "sesman"
            if pidofproc -p  $PIDDIR/xrdp-sesman.pid /usr/local/sbin/xrdp-sesman  > /dev/null; then
                log_progress_msg "running"
                log_end_msg 0
            else
                log_progress_msg "apparently not running"
                log_end_msg 1 || true
                exitval=1
            fi
        fi
        exit $exitval
        ;;
  *)
	N=/etc/init.d/$NAME
	echo "Usage: $N {start|stop|restart|force-reload|status}" >&2
	exit 1
	;;
esac

exit 0

<—- End of the Script ——->

Restart the xrdp service and should see that the error is gone.

 

Issue 2 – First xRDP connection fails

 

This one take us a little bit more time to figure out.  The symptoms are the following.  You have performed a custom installation of xRDP. When you try to connect for the first time to your machine via xRDP, you will get an error message similar to

VNC Error – problem connecting

Click on Picture for better Resolution 

We then checked the /var/log/xrdp/xrdp.log where we have retrieved another error message stating that

Listening socket is in wrong state….

Click on Picture for better Resolution 

If you try again, just after this error, you will be able to connect with no problem to your xRDP session.

Here again, the fix was quite easy.  Actually, the problem is that when you perform the first connection, the vnc service is not ready to answer the request.  In other words, at the first connection, the VNC service is not able to respond to the request.  To fix this issue, we need to introduce a delay when performing the connection.

We will need to edit the /etc/xrdp/xrdp.ini file, go to the section that old the xVNC-Sesman (or xVnc-Sesman-Griffon if you have used our script to perform the custom installation) and append at the end of the section the value delay_ms=2000

[xrdp1]
name=sesman-Xvnc
lib=libvnc.so
username=ask
password=ask
ip=127.0.0.1
port=-1
delay_ms=2000

After performing this change, you will be able to connect at the first login attempt.

However, this change introduce another small modification in the login behaviour of xRDP.  If you perform this change, you will not see the windows log displayed when you perform the login process.  This can be seen as a good thing because it make the login experience more straightforward.  On the other hand, if you need to troubleshoot your connection, you might want to comment or remove the delay and have the window log back to visible.

Final Notes

This is it for this post.  We like to perform the custom xrdp installation because it bring some small changes that make the xrdp software not working as expected. This situation offers us a good way to learn and see how xrdp is really working.

I hope you enjoyed.

Till next time

See ya

4 thoughts on “Tips – xRDP Custom Installation Possible Issues and Solutions

  1. Hey Carsten,

    Thank you for the feedback and the visit….
    Yep, The future will be browser based for remote session…

    Till next time
    See ya

  2. whenever I connect by remote its working perfectly,
    but Im facing an issue that even im surfing around the Ubuntu 20.04 but still facing suspend issue
    the Ubuntu goes to sleep in two cases:
    1- change the power from cord to battery
    2- exceed 10 min

    please check if this is a remote script need to be optimized or need ubuntu tweak

    thanks for your great efforts

  3. @Amjad,

    Ok; never had this issue because we are not really using laptops…The script only perform the installation and does not change Power management configuration settings. So, our guess would be that this is more related to Power management settings
    Thanks for your visit and for sharings your findings
    Till next time
    See ya

Leave a Reply