4

I'm using Lubuntu 14.04 with Openbox 3.5.2.
There are one-liners for locking the screen: dm-tool lock
and for popping up the quit menu: lxsession-default quit

However, if I need to perform a suspend, I need to pop up mentioned menu first,
then navigate to 'Suspend' option and press enter.

Can it be done with a single command?

vucalur
  • 266

3 Answers3

5

You can suspend from the terminal with:

sudo pm-suspend

In some cases, calling pm-suspend directly can cause problems with wi-fi drivers and other programs. Moreover, the man page for pm-suspend says that while it is ok to call it from the command line, it's normally intended to be called through your desktop power manager.

The man page adds that when called from the command line, "it is not guarenteed that all of your programs in your desktop session keep working as expected."

Most of the problems seem to be from services or modules not stopped or unloaded before the suspend. For a good discussion of this issue, along with ways to work around it, see Suspend to Ram in the Arch wiki.

The Arch Wiki also suggests allowing a particular user to run pm-suspend without sudo through visudo to add the following line to /etc/sudoers:

username  ALL = NOPASSWD: /usr/sbin/pm-suspend

LXDE uses the xfce4-power-manager, which uses pkexec to call pm-suspend. pkexec allows execution of a program as another user, in this case root.

The authentication is handled by polkit. It would normally prompt for a password, but as I learned from pkexec with no password it is possible to suppress this through a file in /usr/share/polkit-1/actions.

There's a file there called org.freedesktop.upower.policy (upower is involved in calling pm-suspend but I left it out for simplicity).

This file contains the line <allow_active>yes</allow-active>, which is what allows the action to proceed without asking for a password.

Power-related actions are much more complicated than locking the screen or bringing up the menu. It may be better to use the suspend option in the power manager.

If your suspend function-key works, you might find that convenient. If it doesn't appear to work at first, check the settings in the power manager. In Lubuntu, the sleep button is not set to suspend by default.

You may also enjoy working through the issues at the Arch page in order to use pm-suspend directly. But be careful. I've used the command directly on several other laptops with no problem. On this particular laptop (Lenovo S10-3) it killed the wifi driver. I had to unplug the CMOS battery to get it working again.

chaskes
  • 15,536
2

Sure,

you can try this:

echo mem > /sys/power/state 

maybe you have to be sudo to run it.

1

This can be done through DBus no need for sudo or higher privileges. You may create an alias or script for it.

dbus-send --session --dest=org.freedesktop.PowerManagement \
 /org/freedesktop/PowerManagement \
 org.freedesktop.PowerManagement.Suspend

Better to explore for all available option using d-feet.

  1. Install d-feet

    sudo apt-get install d-feet
    
  2. Follow

    D-Feet → Session Tab
    org.freedesktop.PowerManagement
    /org/freedesktop/PowerManagement
    org.freedesktop.PowerManagemenl

    D-Feet → System or Session tab
    <dbus-name>
    <object-path>
    <interface>: list of methods, properties & signals

References:

  • man dbus-send
  • /usr/share/dbus-1/interfaces/org.freedesktop.PowerManagement.xml

    /usr/share/dbus-1/services/ for session bus
    /usr/share/dbus-1/system-services/ for system bus

    /usr/share/dbus-1/interfaces/ interfaces from both

    Accessing system bus service most need root privileges or policy edit polkit. See chaskes answer.

user.dz
  • 49,176