Re: gnome-session: how to shutdown gnome-session from root?

On date Saturday 2006-12-09 01:42:13 +0530, Ritesh Khadgaray wrote:
> On Fri, 2006-12-08 at 19:33 +0100, Stefano Sabatini wrote:
> > Hi Ritesh, and thanks for your reply.
> > 
> > On date Friday 2006-12-08 22:22:35 +0530, Ritesh Khadgaray wrote:
> > > On Fri, 2006-12-08 at 15:43 +0100, Stefano Sabatini wrote:
> > > > Hi all, 
> > > > 
> > > > I would like like to setup acpid to automatically launch the
> > > > gnome-session-save program when the power button is pressed (and gnome
> > > > is running).
> there were talks with gnome-power-manager on this. not too sure, where
> or what it was about.

gnome-power-manager is very fine, and it supports out of the box the
power button event, that triggers the very gnome-session-save --kill

The only problem is that it isn't as configurable as a script (I can't
actually change the command executed for each event).

> try using dbus system wide service. 
> python scripts are your friend.

I should actually send a message to the gnome-session process using
D-bus, and I actually don't know very well neither the D-bus
communication model, neither python programming :-(...

In each case, while the D-bus/python scripting seems to be the "right"
solution (or maybe even some dbus-send command could be sufficient?)
I've worked around the following fix, maybe a little too
"overkilling", that manages either the case when gnome-power-manager
is not installed.

1) added in the startup programs list (gnome-session-properties) the
echo $SESSION_MANAGER > ~/tmp/gnome-session-manager

2) wrote this script and placed it in /usr/local/sbin/kill-gnome-session

#! /bin/bash
set -e

gnome_session_user=$(ps -e -o command,user | awk '/gnome-session/ { print $2 }')
SESSION_MANAGER=$(cat /home/$gnome_session_user/tmp/gnome-session-manager)

gnome-session-save --gui --kill

3) modified the /etc/acpi/power-button script in this way: 
#! /bin/bash
# Initiates a shutdown when the power putton is pressed.

if ps -e -o command | grep -q '[k]desktop'; then
if ps -e o command | grep -q '[g]nome-session'; then
if  ps -e o command | grep -q '[g]nome-power-manager'; then

if [ "$kdesktop" ] && [ -f /usr/bin/dcop ]; then
    dcop --all-sessions --all-users ksmserver ksmserver logout 0 2 0 && exit 0
elif [ "$gnome_session" ]; then 
    if [ "$gnome_power_manager" ]; then         
    # don't do nothing: gnome-manager knows what to do         
    elif [ -f /usr/bin/gnome-session-save ]; then
    /sbin/shutdown -h now "Power button pressed"

Stefano Sabatini
Linux user number 337176 (see

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]