Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I've been trying to get my ubuntu restart without having to edit the sudoers. This has been possible before (in lucid I think) using a dbus command:

dbus-send –system –print-reply –dest=org.freedesktop.ConsoleKit /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Restart

But this gives me an error. Looks like things have changed.

In KDE (which I don't use) one has something similar (see this answer)

Could anyone show me an alternative way to make my machine reboot from a script (without adjusting rights)

share|improve this question
add comment

2 Answers

up vote 11 down vote accepted

From Launchpad Question #85949:

Logout

dbus-send --session --type=method_call --print-reply --dest=org.gnome.SessionManager /org/gnome/SessionManager org.gnome.SessionManager.Logout uint32:1

Reboot

dbus-send --session --type=method_call --print-reply --dest=org.gnome.SessionManager /org/gnome/SessionManager org.gnome.SessionManager.RequestReboot

Shutdown

dbus-send --session --type=method_call --print-reply --dest=org.gnome.SessionManager /org/gnome/SessionManager org.gnome.SessionManager.RequestShutdown

If some application is inhibiting logout/reboot/shutdown, no action will be performed and gnome-session will show a confirmation dialog.

So add the command:

dbus-send --session --type=method_call --print-reply --dest=org.gnome.SessionManager /org/gnome/SessionManager org.gnome.SessionManager.Logout uint32:1

to your script.

UPDATE: The DBus interface for suspend and hibernate has been removed, to suspend and hibernate from the command line, use pmi Install powermanagement-interface:

  • Suspend:

    pmi action suspend  
    
  • Hibernate:

    pmi action hibernate
    
share|improve this answer
    
where did you get these commands from? –  Quamis Nov 30 '10 at 11:06
    
@Quamis There is a link at the top of my answer. –  Alvin Row Nov 30 '10 at 15:33
add comment

apt-get of pmi in 10.10, installs powermanagement-interface, when pmi action suspend or pmi action hibernate called, returns ServiceUnknown error

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.