more robust version, including force-stop option
This commit is contained in:
parent
49301fac00
commit
68f38adaa3
166
instfiles/init.d/xrdp
Executable file → Normal file
166
instfiles/init.d/xrdp
Executable file → Normal file
@ -1,83 +1,183 @@
|
|||||||
#! /bin/sh
|
#!/bin/sh -e
|
||||||
#
|
#
|
||||||
# start/stop xrdp and sesman daemons
|
# start/stop xrdp and sesman daemons
|
||||||
|
#
|
||||||
### BEGIN INIT INFO
|
### BEGIN INIT INFO
|
||||||
# Provides: xrdp
|
# Provides: xrdp
|
||||||
# Required-Start: $network $remote_fs
|
# Required-Start: $network $remote_fs
|
||||||
# Required-Stop: $network $remote_fs
|
# Required-Stop: $network $remote_fs
|
||||||
# Default-Start: 2 3 4 5
|
# Default-Start: 2 3 4 5
|
||||||
# Default-Stop: 0 1 6
|
# Default-Stop: 0 1 6
|
||||||
# Short-Description: start xrdp daemon
|
# 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
|
### END INIT INFO
|
||||||
|
|
||||||
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
|
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
|
||||||
DAEMON=/usr/sbin/xrdp
|
DAEMON=/usr/sbin/xrdp
|
||||||
PIDDIR=/var/run/xrdp
|
PIDDIR=/var/run/xrdp/
|
||||||
|
SESMAN_START=yes
|
||||||
#USERID=xrdp
|
#USERID=xrdp
|
||||||
# for now X11rdp sessions require root - should be fixed in the future
|
# the X11rdp backend only works as root at the moment - GH 20/03/2013
|
||||||
USERID=root
|
USERID=root
|
||||||
RSAKEYS=/etc/xrdp/rsakeys.ini
|
RSAKEYS=/etc/xrdp/rsakeys.ini
|
||||||
NAME=xrdp
|
NAME=xrdp
|
||||||
DESC=xrdp
|
DESC="Remote Desktop Protocol server"
|
||||||
|
|
||||||
test -x $DAEMON || exit 0
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
force_stop() {
|
||||||
|
|
||||||
|
DELAY=1
|
||||||
|
PROCLIST="xrdp-sesman xrdp-sessvc xrdp-chansrv X11rdp Xvnc"
|
||||||
|
|
||||||
|
for p in $PROCLIST; do
|
||||||
|
pgrep -x $p >/dev/null && pkill -x $p
|
||||||
|
sleep $DELAY
|
||||||
|
pgrep -x $p >/dev/null && pkill -9 -x $p
|
||||||
|
done
|
||||||
|
# let's not kill ourselves - the init script is called xrdp as well
|
||||||
|
pgrep -fx $DAEMON >/dev/null && pkill -fx $DAEMON
|
||||||
|
sleep $DELAY
|
||||||
|
pgrep -fx $DAEMON >/dev/null && pkill -9 -fx $DAEMON
|
||||||
|
|
||||||
|
rm -f $PIDDIR/xrdp*.pid
|
||||||
|
}
|
||||||
|
|
||||||
if [ -r /etc/default/$NAME ]; then
|
if [ -r /etc/default/$NAME ]; then
|
||||||
. /etc/default/$NAME
|
. /etc/default/$NAME
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check for pid dir
|
# Tasks that can only be run as root
|
||||||
if [ ! -d $PIDDIR ] ; then
|
if [ "$(id -u)" = "0" ]; then
|
||||||
|
# Check for pid dir
|
||||||
|
if [ ! -d $PIDDIR ] ; then
|
||||||
mkdir $PIDDIR
|
mkdir $PIDDIR
|
||||||
fi
|
fi
|
||||||
chown $USERID:$USERID $PIDDIR
|
chown $USERID:$USERID $PIDDIR
|
||||||
|
|
||||||
# Check for rsa key
|
# Check for rsa key
|
||||||
if [ ! -f $RSAKEYS ] || cmp $RSAKEYS /usr/share/doc/xrdp/rsakeys.ini > /dev/null; then
|
if [ ! -f $RSAKEYS ] || cmp $RSAKEYS /usr/share/doc/xrdp/rsakeys.ini > /dev/null; then
|
||||||
echo "Generating xrdp RSA keys..."
|
log_action_begin_msg "Generating xrdp RSA keys..."
|
||||||
(umask 077 ; xrdp-keygen xrdp $RSAKEYS)
|
(umask 077 ; xrdp-keygen xrdp $RSAKEYS)
|
||||||
chown $USERID:$USERID $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
|
fi
|
||||||
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
start)
|
start)
|
||||||
echo -n "Starting $DESC: "
|
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 \
|
start-stop-daemon --start --quiet --oknodo --pidfile $PIDDIR/$NAME.pid \
|
||||||
--chuid $USERID:$USERID --exec $DAEMON
|
--chuid $USERID:$USERID --exec $DAEMON >/dev/null
|
||||||
echo -n "$NAME"
|
exitval=$?
|
||||||
[ "$SESMAN_START" = "yes" ] && { \
|
if [ "$SESMAN_START" = "yes" ] ; then
|
||||||
|
log_progress_msg "sesman"
|
||||||
start-stop-daemon --start --quiet --oknodo --pidfile $PIDDIR/xrdp-sesman.pid \
|
start-stop-daemon --start --quiet --oknodo --pidfile $PIDDIR/xrdp-sesman.pid \
|
||||||
--exec /usr/sbin/xrdp-sesman
|
--exec /usr/sbin/xrdp-sesman >/dev/null
|
||||||
echo -n " sesman"
|
value=$?
|
||||||
}
|
[ $value -gt 0 ] && exitval=$value
|
||||||
echo "."
|
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)
|
stop)
|
||||||
|
check_root
|
||||||
[ -n "$XRDP_UPGRADE" -a "$RESTART_ON_UPGRADE" = "no" ] && {
|
[ -n "$XRDP_UPGRADE" -a "$RESTART_ON_UPGRADE" = "no" ] && {
|
||||||
echo "Upgrade in progress, no restart of xrdp."
|
echo "Upgrade in progress, no restart of xrdp."
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
echo -n "Stopping $DESC: "
|
exitval=0
|
||||||
start-stop-daemon --stop --quiet --oknodo --pidfile $PIDDIR/xrdp-sesman.pid \
|
log_daemon_msg "Stopping RDP Session manager "
|
||||||
--chuid $USERID:$USERID --exec /usr/sbin/xrdp-sesman
|
log_progress_msg "sesman"
|
||||||
echo -n "sesman "
|
if pidofproc -p $PIDDIR/xrdp-sesman.pid /usr/sbin/xrdp-sesman > /dev/null; then
|
||||||
start-stop-daemon --stop --quiet --oknodo --pidfile $PIDDIR/$NAME.pid \
|
start-stop-daemon --stop --quiet --oknodo --pidfile $PIDDIR/xrdp-sesman.pid \
|
||||||
|
--chuid $USERID:$USERID --exec /usr/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
|
--exec $DAEMON
|
||||||
sleep 1
|
value=$?
|
||||||
echo "$NAME."
|
[ $value -gt 0 ] && exitval=$value
|
||||||
|
else
|
||||||
|
log_progress_msg "apparently not running"
|
||||||
|
fi
|
||||||
|
log_end_msg $exitval
|
||||||
;;
|
;;
|
||||||
restart)
|
force-stop)
|
||||||
$0 stop
|
$0 stop
|
||||||
|
# because it doesn't allways die the right way
|
||||||
|
force_stop
|
||||||
|
;;
|
||||||
|
restart|force-reload)
|
||||||
|
check_root
|
||||||
|
$0 stop
|
||||||
|
# Wait for things to settle down
|
||||||
|
sleep 1
|
||||||
$0 start
|
$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/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
|
N=/etc/init.d/$NAME
|
||||||
# echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
|
echo "Usage: $N {start|stop|restart|force-reload|status}" >&2
|
||||||
echo "Usage: $N {start|stop|restart|force-reload}" >&2
|
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
Loading…
Reference in New Issue
Block a user