hi all, 

I don't know if anyone is yet working on this project or even reading this mail 
Neither do I know who I should mail so I try all of you. (I found your names in 
relations to the xrdp project and the rpmforge rpm). 

I would like to suggest a new init script for xrdp. I hope this will be added 
to the xrdp rpms (at least in rpmforge!). 

(If not, please explain me why, what I need to change or what else to do). 
I don't have any experience in adding code to an opensource project, so please 
correct me if I should follow another way. 

Thanks in advance for reading this mail and taking the effort to respond! 

I tested on a CentOS 5.5-64 box using the xrdp-0.4.0-1.el5.rf rpm from 
rpmforge. 

below the code: 

#!/bin/sh 
###BEGIN INIT INFO 
# Provides: XRDP Daemon 
# Required-Start: $network 
# Required-Stop: $network 
# Default-Start: 3 5 
# chkconfig: 35 25 90 
# Description: Custom RDP Daemon 
### END INIT INFO 

# /etc/init.d/xrdp d 
# is init script for XRDP . starts xrdp and sesman. 

# Alexander Swen, alex-x...@swen.nu 

# CHANGELOG: 
# 2010-05-17 A.Swen created (based on initial script xrdp_control.sh by Mark 
Balliet and Jay Sorg) 
# 2010-05-25 A.Swen added "status" function. 

# SETTINGS 
date=$(date +%Y%m%d) 
me=$(basename $0) 
mydir=$(dirname $0) 

XRDP=xrdp 
SESMAN=sesman 
STARTWM=startwm.sh 
XRDP_DIR=/usr/lib$([ "$(uname -i)" = "x86_64" ]&& echo 64)/xrdp/ 
LOG=/var/log/xrdp.log 

# FUNCTIONS 
die () { 
rc=$1 
shift 
echo "==== ERROR ====" >&2 
echo $@ >&2 
exit $rc 
} 

usage () { 
echo "Usage: ${me} {start|stop|status|restart|reload|force-reload}" 
exit 1 
} 

# source default functions 
[ -f /etc/SuSE-release ] && distro=suse 
[ -f /etc/redhat-release ] && distro=redhat 
case ${distro} in 
suse) 
[ -f /etc/rc.status ] && . /etc/rc.status 
;; 
redhat) 
[ -f /etc/rc.d/init.d/functions ] && . /etc/rc.d/init.d/functions 
;; 
esac 

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 "." 
return 0; 
} 

is_xrdp_running() { 
ps u --noheading -C $XRDP | grep -q -i $XRDP 
[ $? -eq 0 ] && xrdp_running=1 || xrdp_running=0 
export xrdp_running 
} 

is_sesman_running() { 
ps u --noheading -C $SESMAN | grep -q -i $SESMAN 
[ $? -eq 0 ] && sesman_running=1 || sesman_running=0 
export sesman_running 
} 

check_up() { 
is_sesman_running 
is_xrdp_running 
# Cleanup : If sesman isn't running, but the pid exists, erase it. 
[ ${sesman_running} -eq 0 -a -e /var/run/sesman.pid ] && rm /var/run/sesman.pid 
# Cleanup : If xrdp isn't running, but the pid exists, erase it. 
[ ${xrdp_running} -eq 0 -a -e /var/run/xrdp.pid ] && rm /var/run/xrdp.pid 
return 0; 
} 

# SCRIPT 
[ ${UID} -gt 0 ] && die 0 only root may do that 
[ -d "${XRDP_DIR}" ] || die 1 XRDP_DIR ${XRDP_DIR} not found 

check_up 

cd ${XRDP_DIR} 
[ -x ${XRDP} ] || die 2 XRDP not found or not executable 
[ -x ${SESMAN} ] || die 2 SESMAN not found or not executable 
[ -x ${STARTWM} ] || die 2 STARTWM not found or not executable 
case "$1" in 
status) 
[ ${xrdp_running} -eq 1 ] && echo "xrdp is loaded" 
[ ${sesman_running} -eq 1 ] && echo "sesman is loaded" 
exit 0 
;; 
start) 
[ ${xrdp_running} -eq 1 ] && die 3 "xrdp is already loaded" 
[ ${sesman_running} -eq 1 ] && die 3 "sesman is already loaded" 
xrdp_start 
;; 
stop) 
[ ${xrdp_running} -eq 0 ] && die 3 "xrdp is not loaded" 
[ ${sesman_running} -eq 0 ] && die 3 "sesman is not loaded" 
xrdp_stop 
;; 
force-reload|reload|restart) 
echo "Restarting xrdp ..." 
xrdp_stop 
patience=20 
until [ ${xrdp_running} -eq 0 -a ${sesman_running} -eq 0 ];do 
[ ${patience} -eq 0 ] && die 5 "lost my patience while waiting for xrdp to 
stop" || patience=$((patience-1)) 
check_up 
sleep 1 
check_up 
done 
xrdp_start 
;; 
*) usage ;; 
esac 

exit 0 

------------------------------------------------------------------------------

_______________________________________________
xrdp-devel mailing list
xrdp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/xrdp-devel

Reply via email to