[systemd-devel] login/logout hooks in fedora 17?

Fernando Lopez-Lezcano nando at ccrma.Stanford.EDU
Mon Jun 18 10:04:44 PDT 2012


On 06/18/2012 09:45 AM, Lennart Poettering wrote:
> On Thu, 14.06.12 11:15, Fernando Lopez-Lezcano (nando at ccrma.Stanford.EDU) wrote:
>
> Heya,

Hi Lennart,

>> Any suggestions on how I may run a script when a user logins or logouts
>> of the graphical console? I used to do this with gdm by customizing the
>> Post* and Pre* scripts in /etc/gdm.
>>
>> I see that the login/logout process is (appears to be) controlled by
>> systemd. What would be a good approach to getting the system to run a
>> script before a user logs in and after a user logs out (ie: for local
>> users sitting at the console - probably now called a seat if I
>> understand things correctly).
>>
>> Thanks for any advice!
>
> Hmm, so there are multiple ways to achieve this, but it really depends
> on what you are trying to do here. May I ask what kind of script you
> want to run for a user logging in?

Our workstations have a partition on the hard disk for users to use 
temporarily, mounted under /zap (we've had this for a long long time). 
When a local user (ie: sitting in front of the machine) logs out the 
contents of /zap/ are erased. The partition is usually rather big and 
different from /tmp, /var/tmp, etc (ie: the user should see an empty 
directory when he/she logins).

The script singled out some processes for killing (and log) that could 
spell trouble for subsequent users if they stayed alive (namely jack and 
pd if I remember correctly).

The script also reloads the state of the alsa mixer so that users are 
assured sound will work as expected after they login.

I also used them to track and terminate any user processes that linger 
for a while after the logout, but I believe that can be done now through 
systemd (I think I saw some references to that last week, the name of 
the preference escapes me right now).

Anyway, you get the idea.

> Also do you want this to run prviliged or unprivieleged?

I would prefer privileged, that would allow me, for example, to choose 
what to erase in /zap (not necessarily only the current user's files).

> One possible way is probably to hook this into the PAM session
> setup/shutdown so that you can catch all types of logins with this. If
> you need to run a script rather than write a PAM script a quick google
> search reveals that pam-hooks might be the way to go?
>
> Anyway, I can make a better recommendation with a few hints on the
> intended usecases

BTW, last Friday I tried to use a small perl program using Net::Dbus or 
something like that (sorry, I don't have the code here right now) to try 
to listen to specific messages from the --system bus but while 
everything seemed to run fine and I got no errors I never saw any 
messages (the messages were seen by the standard utility). Based on my 
searches so far that seemed like a reasonable approach.

Thanks!
-- Fernando


More information about the systemd-devel mailing list