summaryrefslogtreecommitdiffstats
path: root/instfiles/xrdp_control1.sh
blob: aede7c0d8747f527155e0342be203166b52f0e68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/bash
# this needs to be a bash script, the first line needs to be #!/bin/bash
# xrdp control script
# same as xrdp_control.sh except the XRDP_DIR is /usr/lib/xrdp
# Written : 1-13-2006 - Mark Balliet - posicat@pobox.com
# maintaned by Jay Sorg
# chkconfig: 2345 11 89
# description: starts xrdp

XRDP=xrdp
SESMAN=sesman
STARTWM=startwm.sh
XRDP_DIR=/usr/lib/xrdp/
LOG=/dev/null

cd $XRDP_DIR

test -x $XRDP || (echo "$XRDP is not executable" ; exit 0)
test -x $SESMAN || (echo "$SESMAN is not executable" ; exit 0)
test -x $STARTWM || (echo "$STARTWM is not executable" ; exit 0)

xrdp_start () {
  echo -n "Starting : xrdp and sesman . . "
  ./$XRDP >> $LOG
  ./$SESMAN >> $LOG
  echo "."
  sleep 1
  return 0
}

xrdp_stop () {
  echo -n "Stopping : xrdp and sesman . . "
  ./$SESMAN --kill >> $LOG
  ./$XRDP --kill >> $LOG
  echo "."
}

check_up () {
  xrdpup=`ps u --noheading -C $XRDP`
  sesup=`ps u --noheading -C $SESMAN`

  # Cleanup : If sesman isn't running, but the pid exists, erase it.
  if [ "$sesup" == "" ]
  then
    if [ -e /var/run/sesman.pid ]
    then
      rm /var/run/sesman.pid
    fi
  fi
  # Cleanup : If xrdp isn't running, but the pid exists, erase it.
  if [ "$xrdpup" == "" ]
  then
    if [ -e /var/run/xrdp.pid ]
    then
      rm /var/run/xrdp.pid
    fi
  fi
}

case "$1" in
  start)
    check_up
    if [ "$xrdpup" != "" ]
    then
      echo "Xrdp is already loaded"
      exit 1
    fi
    if [ "$sesup" != "" ]
    then
      echo "sesman is already loaded"
      exit 1
    fi
    xrdp_start
    ;;
  stop)
    check_up
    if [ "$xrdpup" == "" ]
    then
      echo "xrdp is not loaded."
    fi
    if [ "$sesup" == "" ]
    then
      echo "sesman is not loaded."
    fi
    xrdp_stop
    ;;
  force-reload|restart)
    check_up
    echo "Restarting Xrdp ..."
    xrdp_stop
    while [ "$xrdpup" != "" ]; do
      check_up
      sleep 1
    done
    xrdp_start
    ;;
  *)
    echo "Usage: xrdp_control.sh {start|stop|restart|force-reload}"
    exit 1
esac

exit 0