Changeset 1041

Show
Ignore:
Timestamp:
10/08/06 11:23:16 (2 years ago)
Author:
tushar
Message:

Updated: starting-and-stopping-dbus-with-kdm

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/starting-and-stopping-dbus-with-kdm.txt

    r1038 r1041  
    11AUTHOR: Stef Bon <stef at bononline dot nl> 
    22 
    3 DATE: 2006-07-18 
     3DATE: 2006-09-09 
    44 
    55LICENSE: GNU Free Documentation License Version 1.2 
     
    1010This hint is about starting the sessionpart of the dbusdaemon. This  
    1111is based on my hint  
    12 "Execute scripts at begin and end of a KDE-session using KDM and PAM". 
     12"Execute scripts at begin and end of a KDE-session using KDM". 
    1313 
    1414In this hint is described in general how scripts and commands are  
    15 started at the begin and end of a KDE session using KDM, and for password  
    16 sensitive commands support from PAM. 
    17  
    18 DBUS does not need anything of PAM, so here you'll find how you can start 
    19 and stop the session dbus daemon with KDM. 
     15started at the begin and end of a KDE session using KDM. 
     16 
     17It's very possible to use this construction with oher loginmanagers as well. 
     18 
    2019 
    2120ATTACHMENT: 
     
    33321.2 Starting the sessionbus part of dbus 
    34331.3 Stopping the sessionbus part of dbus 
    35 1.4 Installation of Sudo 1.6.8p7 
     341.4 Installation of Sudo 1.6.8p12 
    36351.5 One user is more than one time logged in 
    3736 
     
    4039--------------------------------------------------------------------------------- 
    4140 
    42 The dbus package is split up in two parts: one systemwide part and one for (each) session/user. 
    43 The systemwide part (a daemon) is started at boottime, with special privileges of a dedicated user. 
    44 The sessionwide part (also a daemon) has to started when a session for a user begins,  
    45 and stopped when the session ends. 
    46  
    47 The construction with kdm I'm using here is ideal for this. One script in the startup directory to 
    48 start the sessiondaemon for a user, running with the privileges of that user, and one in the reset  
    49 directory an other script has to stop that daemon. 
    50  
    51 But is not so simple as that. Some variables (DBUS_SESSION_BUS_ADDRESS and DBUS_SESSION_BUS_PID) have to  
    52 be available in the environment to every application which works with dbus.  
    53 IMHO the setting of these variables should go in the bash-startupscripts. 
    54 Then whatever script or application you're running, these variables are set 
    55 to the right value.  
     41The dbus package is split up in two parts: one systemwide part and one  
     42for (each) session/user. The systemwide part (a daemon) is started at boottime,  
     43with special privileges of a dedicated user. The sessionwide part (also a daemon)  
     44has to started when a session for a user begins, and stopped when the session ends. 
     45 
     46The construction with kdm I'm using here is ideal for this. One script in the  
     47startup directory to start the sessiondaemon for a user, running with the privileges  
     48of that user, and one in the reset directory an other script has to stop that daemon. 
     49 
     50But is not so simple as that. Some variables (DBUS_SESSION_BUS_ADDRESS and  
     51DBUS_SESSION_BUS_PID) have to be available in the environment to every application  
     52which works with dbus. IMHO the setting of these variables should go in the  
     53bash-startupscripts. Then whatever script or application you're running, these  
     54variables are set to the right value.  
    5655 
    5756 
     
    6059---------------------------------- 
    6160 
    62 The sessiondaemon of dbus creates a file which contains the environmentvariables. As stated above this 
    63 file should be read (sourced) by bash when it starts for this user. 
    64  
    65 When bash is started by "login" as an interactive login shell, it reads /etc/profile and ~/.bash_profile. 
    66 Bash is also started by "kdm", and the files /etc/profile and ~/.bash_profile are sourced. 
     61The sessiondaemon of dbus creates a file which contains the environmentvariables.  
     62As stated above this file should be read (sourced) by bash when it starts for this user. 
     63 
     64When bash is started by "login" as an interactive login shell, it reads /etc/profile  
     65and ~/.bash_profile. Bash is also started by "kdm", and the files /etc/profile  
     66and ~/.bash_profile are sourced. 
    6767 
    6868My idea is to store the output of the command 
     
    7474$HOME/.dbus-session 
    7575 
    76 This file is "sourced" when bash start. This happens not automatically, but you will have to add the following script to /etc/profile.d : 
     76This file is "sourced" when bash start. This happens not automatically, but you  
     77will have to add the following script to /etc/profile.d : 
    7778 
    7879cat >> dbus-session.sh << "EOF" 
     
    9697(beginning 200510..).  
    9798 
    98 Create a script in the /etc/session.d/kdm/startup directory dbus-kdm.sh: 
     99Create a script in the /etc/session.d/kdm/startup directory dbus-session-start.sh: 
    99100 
    100101cd /etc/session.d/kdm/startup 
    101102 
    102 cat >> dbus-kdm.sh << "EOF" 
     103cat >> dbus-session-start.sh << "EOF" 
    103104#!/bin/bash 
    104105 
     
    113114 
    114115if [ -d $homedir ]; then 
    115          
    116         # should there be a check dbus-launch is already running for this user? 
    117  
     116 
     117    # 
     118    # do a check whether dbus-daemon is already running 
     119    # dbus-daemon needs to be started by the user (uidnr) logging in 
     120    # 
     121     
     122    if [ -f $homedir/.dbus-session ]; then 
     123 
     124        # do a check the dbus-daemon for this user is running with the pid 
     125        # in the .dbus-session file 
     126  
     127        # pid according to the ps command 
     128        ps_dbus_session_pid=$(ps aux | grep -m 1 -E "^$userid.*dbus-daemon.*session.*" \ 
     129        | grep -v "grep" | sed 's@[[:space:]][[:space:]]*@ @g' | cut -d " " -f 2) 
     130         
     131        # read the pid from the .dbus-session file 
     132        . $homedir/.dbus-session 
     133 
     134 
     135        # check they are the same        
     136        if [ -z "$ps_dbus_session_pid" ]; then 
     137         
     138            # dbus for this user not running 
     139            rm $homedir/.dbus-session 
     140             
     141        elif [ $DBUS_SESSION_BUS_PID -ne $ps_dbus_session_pid ]; then 
     142         
     143            # there is something wrong: stop dbus-daemon for this user  
     144            # and remove .dbus-session file 
     145            if [ $(id -u) -eq 0 ]; then 
     146                sudo -H -u $userid sh -c "kill $ps_dbus_session_pid" 
     147 
     148            elif [ $(id -u) -eq $uidnr ]; then 
     149                kill -SIGTERM $ps_dbus_session_pid; 
     150            fi 
     151 
     152            rm $homedir/.dbus-session 
     153             
     154        fi 
     155     
     156    fi   
     157 
     158    if [ ! -f $homedir/.dbus-session ]; then 
     159 
     160        # only start a dbus session if .dbus-session file it not found 
     161        # in users homedirectory  
     162   
    118163        if [ $(id -u) -eq 0 ]; then 
    119164            sudo -u $userid -H /bin/sh -c "dbus-launch --auto-syntax > $homedir/.dbus-session" 
    120165            retcode=$? 
    121166            chown $uidnr:$gidnr $homedir/.dbus-session 
    122             chmod u+x $homedir/.dbus-session 
    123167        elif [ $(id -u) -eq $uidnr ]; then  
    124168            dbus-launch --auto-syntax > $homedir/.dbus-session 
    125169            retcode=$? 
    126             chmod u+x $homedir/.dbus-session 
    127170        fi 
     171 
     172    fi 
    128173 
    129174fi; 
     
    135180exit $retcode 
    136181EOF 
     182 
     183chmod 755 /etc/session.d/kdm/startup/dbus-session-start.sh 
    137184 
    138185This script, executed by KDM at startup will start the dbus session daemon for this user,  
    139186and will create the .dbus-session file in the homedirectory of this user, containing 
    140187all the dbusvariables. 
     188It will only do this when dbus is not already running for this user. 
    141189 
    142190Now when bash starts at login, it reads (sources) this file. 
     
    160208 
    161209 
    162 Creating the dbus.sh script in the reset directory: 
     210Creating the dbus-session-stop.sh script in the reset directory: 
    163211 
    164212 
    165213cd /etc/session.d/kdm/reset 
    166214 
    167 cat >> dbus-kdm.sh << "EOF" 
     215cat >> dbus-session-stop.sh << "EOF" 
    168216#!/bin/bash 
    169217 
     
    202250EOF 
    203251 
     252chmod 755 /etc/session.d/kdm/reset/dbus-session-stop.sh 
     253 
    204254This script stops the session part of the dbus-daemon. 
    205255 
     
    238288one sessions at the same time? Is it nessacary to start the sessionpart 
    239289of dbus for every session, or is one instance sufficient?  
    240 At this moment I don't have the answer for that question.  
    241 Any has, please let me know. 
    242  
    243 I'll go check out the Internet about it. 
     290 
     291This construction does not allow more than one dbus-daemon per user.  
     292I think that should be good enough.  
     293 
    244294 
    245295ACKNOWLEDGEMENTS: 
     
    252302  * Changed the bash scripts 
    253303  * changed from sudo-1.6.8p7 to sudo-1.6.8p12 
    254  
     304[2006-09-09] 
     305  * add check to see dbus-daemon is already running for this user 
     306    and the information found in .dbus-session is right