Results 1 to 3 of 3

Thread: Execute gnome-power-cmd.sh from PHP script

  1. #1
    Join Date
    Oct 2008
    Beans
    12

    [SOLVED] Execute gnome-power-cmd.sh from PHP script

    Hi everybody, sorry for my English!
    I need to shutdown a computer using a PHP script.

    If I execute 'sudo /sbin/shutdown -h now' it works, but I would like to use '/usr/bin/gnome-power-cmd.sh shutdown' to let Gnome power manager handle the event.
    People say that this is the right way, to avoid filesystem corruptions and so on..

    But '/usr/bin/gnome-power-cmd.sh' uses D-Bus to send the command to the power manager and it seems that PHP (Apache module) doesn't have access to the D-Bus session (the Gnome-power-manager one) because it says: "Failed to open connection to session message bus: dbus-launch failed to autolaunch D-Bus session: Autolaunch error: X11 initialization failed."

    Well, I know nothing about D-Bus..
    Someone knows a way to get it working?
    Last edited by abePdIta; October 23rd, 2008 at 02:03 PM. Reason: Solved!

  2. #2
    Join Date
    Oct 2008
    Beans
    12

    Thumbs down Re: Execute gnome-power-cmd.sh from PHP script

    Ok! Founded a solution, thanks to fede@E-pillole.com.

    Code:
    #!/bin/bash
    
    user=`whoami`
    pid=`pgrep -u $user gnome-panel`
    
    for dbusenv in $pid; do
    	DBUS_SESSION_BUS_ADDRESS=`grep -z DBUS_SESSION_BUS_ADDRESS \
    	/proc/$pid/environ | sed -e 's/DBUS_SESSION_BUS_ADDRESS=//'`
    	
    	DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS \
    	/usr/bin/gnome-power-cmd.sh shutdown
    done
    
    exit 0
    PHP calls this script and it just works..
    Improvements are welcome!

  3. #3
    Join Date
    Feb 2007
    Location
    New York
    Beans
    894
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Execute gnome-power-cmd.sh from PHP script

    Hmmm... there are two commands on https://wiki.ubuntu.com/DebuggingGNOMEPowerManager. Which is better?

    Code:
    dbus-send --system --print-reply --dest="org.freedesktop.Hal" /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Reboot
    Code:
    gnome-power-cmd.sh reboot
    Which is more like the behavior of the Restart command in the System menu? Is the first more cross-platform, or should we find whether the user is running Gnome or KDE first?
    "Please remember to do things the Ubuntu way. There is always more than one solution to a problem, choose the one you think will be the easiest for the user. ... Try to think as a green user and choose the simplest solution." — Code of Conduct

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •