Last Updated: February 25, 2016
·
2.298K
· akiwiguy

Dealing with Xrdp's horrible init script

I needed to install Xrdp on a couple of machines because my thin client doesn't support anything but RDP. Unfortunately, I met it's horribly-written init script that (in my testing) didn't even work properly. So, I wrote a better one.

#!/bin/bash

LOG=/dev/null

is_xrdp_running() {
  ps u --noheading -C xrdp | grep -q -i xrdp
  return $?;
}

is_sesman_running() {
  ps u --noheading -C xrdp-sesman | grep -q -i xrdp-sesman
  return $?;
}

xrdp_start() {
  is_xrdp_running; if [[ $? == 0 ]]; then echo "xrdp is already running"; exit 1;     fi
  is_sesman_running; if [[ $? == 0 ]]; then echo "sesman is already running"; exit 1; fi
  echo -n "Starting xrdp and sesman... "
  /usr/sbin/xrdp >> $LOG
  /usr/sbin/xrdp-sesman >> $LOG
  echo "done."
  return 0;
}

xrdp_stop() {
  is_xrdp_running; if [[ $? == 1 ]]; then echo "xrdp is not running"; exit 1; fi
  is_sesman_running; if [[ $? == 1 ]]; then echo "sesman is not running"; exit 1; fi
  echo -n "Stopping xrdp and sesman... "
  /usr/sbin/xrdp-sesman --kill >> $LOG
  /usr/sbin/xrdp --kill >> $LOG
  echo "done."
  return 0;
}

case "$1" in
  start)
    xrdp_start
    ;;
  stop)
    xrdp_stop
    ;;
  force-reload|restart)
    xrdp_stop
    xrdp_start
    ;;
  *)
    echo "Usage: `basename $0` {start|stop|restart|force-reload}"
    exit 1
esac

exit 0