-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Running a user logout script
Some deployments may find it useful to run a script when a user logs out from an XRDP session.
One way to do this, is to take the startwm.sh
script provided by your distribution and modify it so that the logout script is called when the window manager process exits.
This distribution provides XRDP version 0.9.12-1.
A default XRDP installation has a /etc/xrdp/startwm.sh
script which does the following:-
- Sets up the process environment from
/etc/profile
- Sets up locale-specific environment variables
-
exec
s/etc/X11/xsession
to start the desktop environment.
There are at least three ways to get this script to call a user logout script.
- Modify the distribution-provided
startwm.sh
to call the script. - Take a copy of
startwm.sh
and modify that. Then getsesman
to call the modified script. - Write a totally separate script (called by
sesman
) which calls the original script to implement some of the required functionality.
This description uses the second method. You may prefer to use one of the others, or something different.
- A global script
/usr/local/bin/xrdp_logout
is called when a user logs out. - Optionally, the user can supply an override for this script called
.xrdp_logout
. - The logout process should be loggable.
The original script is written in Bourne shell using a particular style. The modifications we are making here are in the same style. You may prefer to use bash
instead if that suits your environment better.
- Copy
/etc/xrdp/startwm.sh
to/etc/xrdp/startwm_and_logout.sh
, making sure it's executable:-$ sudo cp -p /etc/xrdp/startwm.sh /etc/xrdp/startwm_and_logout.sh
- Edit
/etc/xrdp/startwm_and_logout.sh
. The last two lines look like this:-test -x /etc/X11/Xsession && exec /etc/X11/Xsession exec /bin/sh /etc/X11/Xsession
- Remove these two lines and replace them with the following code. This works the same as the code it's replacing, except that control returns to the calling script when the session finishes.
Then append the extra functionality to the end of the script:-
if test -x /etc/X11/Xsession; then /etc/X11/Xsession else /bin/sh /etc/X11/Xsession fi
USER_LOGOUT=$HOME/.xrdp_logout SYSTEM_LOGOUT=/usr/local/bin/xrdp_logout # Set up a log file if the data home directory is available test -z "$XDG_DATA_HOME" && XDG_DATA_HOME=$HOME/.local/share if test -d "$XDG_DATA_HOME"; then exec >"$XDG_DATA_HOME/xrdp/xrdp_logout_$DISPLAY.log" 2>&1 fi if test -r $USER_LOGOUT; then if test -x $USER_LOGOUT; then $USER_LOGOUT else /bin/sh $USER_LOGOUT fi elif test -r $SYSTEM_LOGOUT; then if test -x $SYSTEM_LOGOUT; then $SYSTEM_LOGOUT else /bin/sh $SYSTEM_LOGOUT fi fi exit 0
- Edit
/etc/xrdp/sesman.ini
. SetDefaultWindowManager=startwm_and_logout.sh
sudo systemctl restart xrdp-sesman