Start Service or Script at user logout

Hello Community,

i am new to Alma Linux 8.4 and i want to user AlmaLinux as an xRDP Server.
For my Session Directory, i have a Python script, that is running at user login and logout.

My problem is:
The connection via xRDP loads the target user profile, so i was able to run my login_script.py at login by configuring the user home ~/.bash_profile.

At user logout from xRDP Server, i configured the ~/.bash_logout to run my logout_script.py but my script sadly does not run at logout from xRDP.

I also have a Citrix VDA Linux Client. This one runs my script at ~/.bash_logout.

I also tried a user Service for login and logout via systemd but without success.

can anyone help me?

@Baki welcome to the ALMA Linux Forums.

Just a couple of question to help you diagnose the problem for yourself.

  1. Do you have the mailx package installed so that when events that would normally hit the console get routed to mail and saved as a message for root?

  2. What are the perms on the python script and is it in a path that is widely available to all users that you want this script to execute for?

If you have the mailx package installed and you have print, printf or echo statements to “the screen/console” then run your test to see if the statements are printed (not likely yet because you have not made any changes), then log back in and check root’s mail.

Assuming that you do not know how to run the mail command, installed with the mailx package, you could use this Youtube video to learn how to check mail messages:
Admin@LearnRHEL - Int.001 - Checking Root’s mail but you will have to install mailx first.

Hello Warron and thanks for your reply,

  1. My script output gets to a txt file to /tmp/logon and /tmp/logout, so i can verify that way, whether the script was running or not.

  2. The perms on the python script are 777. I tried a chmod +x first and that was running there as well.

Sadly i also tried to edit my user@.service like this:

SPDX-License-Identifier: LGPL-2.1+

This file is part of systemd.

systemd is free software; you can redistribute it and/or modify it

under the terms of the GNU Lesser General Public License as published by

the Free Software Foundation; either version 2.1 of the License, or

(at your option) any later version.

[Unit]
Description=User Manager for UID %i
After=systemd-user-sessions.service
After=user-runtime-dir@%i.service
Requires=user-runtime-dir@%i.service

[Service]
User=%i
PAMName=systemd-user
Type=notify
ExecStart=-/usr/lib/systemd/systemd --user
Slice=user-%i.slice
KillMode=mixed
Delegate=pids memory
TasksMax=infinity
TimeoutStopSec=120s
ExecStop=-/usr/bin/true
ExecStopPost=-/etc/profile.d/startlogout.sh

And my startlogout is written like the following text
#!/bin/bash
/usr/bin/python3 /etc/profile.d/writelogout.py:

The problem there is, that the user@.service for my user runs ExecStart AND ExecStop at about the same time. That is working the same way with my own systemd service for users.

Sorry @Baki, I misunderstood the original premise of the problem; or rather yet the deeper details.

I found these links, hoping to be helpfu;l in this case: