I'm trying to do some stuff at logout, and the task can take up to 5 minutes to complete.
If the user chooses Power off
or Reboot
directly, the script is killed before completion. If the user just chooses Log out
, the script is executed with no problems.
I've tried using pam_exec
and lightdm
property session-cleanup-script
to point to my script, but it's the same in both cases.
The script used to do the testing is this one:
#!/bin/bash
touch /tmpfile
for p in $(seq 0 300) ; do
sleep 1
echo $p >> /tmpfile
done
When logging out, all the 300 numbers are written to the file. When shutting down or rebooting directly from within the user session, only 2 or 3 numbers are written, so the script is being killed.
How is handled the shutdown by lightdm? How can I ensure my script is not being killed?
If you propose an alternative approach, please take care that I need to know what user is being logged out and be able to run a script as that user. I also need to notify the user about what's happening, so better stay on X if possible.