[systemd] Toggle whether lid close makes laptop sleep

Before migrating to systemd, I had a nice setup using laptop-mode where I would use the laptop "Sleep key" as a toggle for whether closing the lid put the laptop into sleep mode or not. This was just a few lines reading/writing to a file ~/.lidsleep, which I hacked into the laptop-mode shell scripts. Having switched to systemd, and wanting to do the same the "systemd way", I've come up short.
What I have managed to do is temporarily disable the "lid -> sleep" action, with this command:
   # systemd-inhibit --what=handle-lid-switch cat
where the function of the final `cat` is to be a program that does not return until I type ^C.
I basically have two questions:
1) How can I make systemd perform an arbitrary command when I press the "Sleep key"?
2) Short of something like running `pgrep systemd-inhibit && pkill systemd-inhibit || systemd-inhibit --what=handle-lid-switch cat`, what is the best way to setup a toggle like this?
Final bonus question, if these two are answered:
My previous setup also included restoring the toggle to its default state (lid -> sleep : yes) when resuming from hibernate (not suspend). How would I do this using systemd?

As WonderWoofy suggests, why not just tell systemd to not handle lid close or the sleep key (not sure it does that but if it does) and continue to use your existing solution with laptop mode tools?
systemd is not, that I know of, supposed to handle stuff like key presses and it is deliberately designed so that you can have a more sophisticated system hand events such as lid closing and so on. Moreover, it doesn't replace the remaining functionality of laptop-mode tools so assuming you used that for other things too, you'll need it anyway. That is, I can't even see how this would let you uninstall laptop-mode tools if you've been using it without giving up a bunch of other stuff. Could you explain why you want to do it without laptop-mode tools etc.?

Similar Messages

  • Lid closing and laptop doesn't sleep

    I have my setting so that when the lid closes the laptop goes to sleep (plugged in or on battery).  However, the laptop does not always go to sleep.  Sometimes it will stay on for hours until it dies completely.  Any idea what could be keeping the laptop from going to sleep when the lid is closed?  Also, it gets VERY hot and dies out in about 2.5-3 hours (though I do have it set on high performance mode).  That's pretty disconcerting especially that the screen is off.  

    Good evening.
    Could you provide a bit more information about your PC (model, Windows version, etc)?
    Regards.
    English Community   Deutsche Community   Comunidad en Español   Русскоязычное Сообщество
    Community Resources: Participation Rules • Images in posts • Search (Advanced) • Private Messaging
    PM requests for individual support are not answered. If a post solves your issue, please mark it so.
    X1C3 Helix X220 X301 X200T T61p T60p Y3P • T520 T420 T510 T400 R400 T61 Y2P Y13
    I am not a Lenovo employee.

  • [SOLVED] Run xscreensaver when I close the laptop lid

    I have xscreensaver running in my archlinux, and with a systemd service, I can start it after waking up my laptop.
    The problem is that I like to keep my laptop running when I close the lid (for example, to go to bed while I'm downloading a file, I like to simply close my lid), but I want to lock my computer.
    In the /etc/systemd/logind.conf, there is a nice option called HandleLidSwitch, which specifies which action is invoked when the lid is closed, and there is a lock option, but It doesn't work for me.
    The option suspend works fine.
    Here is my /etc/systemd/logind.conf:
    # This file is part of systemd.
    # systemd is free software; you can redistribute it and/or modify it
    # under the terms of the GNU Lesser General Public License as published by
    # the Free Software Foundation; either version 2.1 of the License, or
    # (at your option) any later version.
    # See logind.conf(5) for details
    [Login]
    #NAutoVTs=6
    #ReserveVT=6
    #KillUserProcesses=no
    #KillOnlyUsers=
    #KillExcludeUsers=root
    #Controllers=
    #ResetControllers=cpu
    #InhibitDelayMaxSec=5
    HandlePowerKey=suspend
    #HandleSuspendKey=suspend
    #HandleHibernateKey=hibernate
    HandleLidSwitch=ignore
    #PowerKeyIgnoreInhibited=no
    #SuspendKeyIgnoreInhibited=no
    #HibernateKeyIgnoreInhibited=no
    #LidSwitchIgnoreInhibited=yes
    #IdleAction=ignore
    #IdleActionSec=30min
    Any help?
    Last edited by alomsimoy (2013-09-10 18:08:33)

    I would say that you should just have logind ignore the LidSwitch altogether.  So if it is set to ignore the lid switch, then it obviously isn't going to be entering the suspend.target (or is it the sleep.target, I can't remember).  Therefore, you are going to have to have some other way of triggering actions in response to these events.
    The lid switch sends an event to udev, so you have the option of having a udev rule that responds to this, or using acpid to start this for you.  I would recommend using acpid, as it is much more flexible in what it can allow you to do.
    Edit: acpid is not necessarily more flexible than a udev rule, as it relies on the udev events.  But it is a much easier method of setup since it simply relies of basic scripting in order to make it work.  It can allow for one central script (or collection of scripts) to handle all the different events that udev sends.  To see what kinds of things trigger a udev event, you can use udevadm monitor or if you install acpid, there is the acpi_listen option.
    Edit2:  BTW, what is it you mean by not working?  Does it still suspend on lid close, or is your xscreensaver not started?  You need to be more explicit there.  If it is still suspending, have you rebooted or restarted logind after making those changes to logind.conf?  You can't just edit the file and have the changes implemented right away, as the configuration is parsed and the settign implemented on the service start.
    Last edited by WonderWoofy (2013-09-10 17:28:05)

  • [SOLVED] Laptop Lid Close

    I've been using arch on my laptop for a while now and have been having problems when I close the lid on my laptop. What I want my a laptop to do is nothing except simply turn the screen off when the lid is shut. However, at the moment when I close the lid, it doesn't suspend or sleep or anything, the screen turns off, but when I open the lid, I am presented with a black screen(lit up). I have to turn my laptop on and off to use it again, or change tty and then restart the x-screen. Any help would be much appreciated. Thanks in advance.
    Last edited by compty (2013-12-30 08:15:22)

    Thanks,
    I'm using acpid to handle the event and in the /etc/systemd/logind.conf I have only the following line uncommented:
    HandleLidSwitch=ignore
    Which to my understanding should prevent systemd from controlling the event yes?
    And at the moment I currently have the default acpi setup,
    so the anything event:
    # Pass all events to our one handler script
    event=.*
    action=/etc/acpi/handler.sh %e
    And the following hander.sh:
    #!/bin/bash
    # Default acpi script that takes an entry for all actions
    case "$1" in
    button/power)
    case "$2" in
    PBTN|PWRF)
    logger 'PowerButton pressed'
    logger "ACPI action undefined: $2"
    esac
    button/sleep)
    case "$2" in
    SLPB|SBTN)
    logger 'SleepButton pressed'
    logger "ACPI action undefined: $2"
    esac
    ac_adapter)
    case "$2" in
    AC|ACAD|ADP0)
    case "$4" in
    00000000)
    logger 'AC unpluged'
    00000001)
    logger 'AC pluged'
    esac
    logger "ACPI action undefined: $2"
    esac
    battery)
    case "$2" in
    BAT0)
    case "$4" in
    00000000)
    logger 'Battery online'
    00000001)
    logger 'Battery offline'
    esac
    CPU0)
    *) logger "ACPI action undefined: $2" ;;
    esac
    button/lid)
    case "$3" in
    close)
    logger 'LID closed'
    open)
    logger 'LID opened'
    logger "ACPI action undefined: $3"
    esac
    logger "ACPI group/action undefined: $1 / $2"
    esac
    # vim:set ts=4 sw=4 ft=sh et:
    I know I need to add the commands etc to perform the various functions, but I thought that this handler.sh would do nothing?
    I'm also using xfce. My laptop is a Dell Inspiron 7720.
    Any advice on what I might be doing wrong?

  • [SOLVED] Power button and laptop lid close rules not followed (KDE)

    I'm using KDE 4.9.1, and the rules I set for the power button and lid close events in the KDE power management settings are not followed.
    Currently, I have the power button press event set to trigger hibernation, and the lid close event set to turn off the display. Instead, the power button causes the laptop to power down immediately, as if the 'poweroff' command was issued. Closing the lid causes the system to suspend to ram.
    This problem seemed to have started when I installed 'laptop-mode-tools' and 'acpid'. The problem persisted even when I uninstalled the said packages from the system. Most solutions on the internet involve adjusting the contents of files in /etc/acpi/, but that directory does not exist on my system. I also tried deleting the power management configuration files in the ~/.kde4/share/config directory, but that didn't fix the problem either.
    Hibernation works if I choose 'hibernate' from the KDE menu.
    Thanks for any help.
    Last edited by rb3 (2012-09-28 05:46:56)

    That's not a good solution.
    Changes in systemd default behaviour are reasonable. It guarantees that if your graphical enviroment has no suspend support, it will still suspend when the lid is closed.
    For example, closing the laptop lid at KDM login screen will now suspend the laptop. I remember a topic when someone nearly killed his notebook battery with overheat in that situation (the laptop did not suspend when the lid was closed at kdm screen).
    This change also brings native (non-acpid) suspend support to lighweight desktop enviroments.
    The source of the «double suspend» problem is in acynchronized update of systemd and KDE.
    Updating KDE to 4.9.2 (which will be released in several days) will fix this without editing the config file.
    Make sure you restore the original logind.conf after updating to KDE 4.9.2.
    See:
    http://lists.freedesktop.org/archives/s … 06604.html
    https://bugs.kde.org/show_bug.cgi?id=307412
    https://git.reviewboard.kde.org/r/106533/

  • Internet Connection off when Laptop Lid Closes

    Hi. I just bought my first Mac. A macbook pro. I like to leave my AIM or Ichat on but would like to close the lid to my laptop. Everytime I do, it logs me off. I think this is because of the sleep function. Is there a way to configure so that it doesnt lose my internet everytime???

    nope, it is a physical hardware switch that disables the internet when the lid is closed. the only way to disable it is to use your computer in clamshell mode, which means you need an exteral moniter, keyboard, and mouse

  • Laptops in docking station with lid closed go to sleep during in-place migration from XP to Windows 7

    We have an issue where existing XP laptops are targeted with SCCM 2012 OSD TS for upgrade to Windows 7.  The laptops are in a docking station, with the lid closed.  The laptops are going to sleep when the OSD is booted in WinPE, just before the
    Setup Windows and Configmgr step.  I have copied powercfg.exe from a Windows 8.1 machine (both AMD64 and x86 versions) to the MDT Tool package...." and then a step to run:
    %DeployRoot%\Scripts\%PROCESSOR_ARCHITECTURE%\PowerCfg.exe -setacvalueindex 381b4222-f694-41f0-9685-ff5bb260df2e 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 0
    However, the laptops are still sleeping during the Setup Windows and Configmgr step.   Any insight to correcting this will be extremely helpful.

    Hi
    We came across this issue, seems odd that SCCM doesn't suspend the power management in the OS during the TS - (But then again it also seems odd that Windows 7 will go to sleep if you close the lid of a laptop half way through a shutdown, so that when you
    lift the lid it wakes only to complete the shutdown, did MS not spot that, or choose to ignore it!?).
    These commands should be run soon after the Setup Windows and ConfigMgr step and will disable the device and screen from sleep/hibernating:
    Prevent sleep during OSD (Battery power)
    cmd.exe /c powercfg -x -standby-timeout-dc 0
    Prevent sleep during OSD (AC power)
    cmd.exe /c powercfg -x -standby-timeout-ac 0
    Prevent monitor off during OSD (Battery power)
    cmd.exe /c powercfg -x -monitor-timeout-dc 0
    Prevent monitor off during OSD (AC power)
    cmd.exe /c powercfg -x -monitor-timeout-ac 0
    Prevent hibernate during OSD (Battery power)
    cmd.exe /c powercfg -x -hibernate-timeout-dc 0
    Prevent hibernate during OSD (AC power)
    cmd.exe /c powercfg -x -hibernate-timeout-ac 0
    At the end of the TS, you can revert these changes by running the following command to reset the power scheme:
    powercfg -restoredefaultschemes
    Hope this helps
    Thank you.  However, we did put similar steps in our Task Sequence right after the "Setup Windows and..." step, but the issue we are having is that the "Sleep" occurs during the "Setup Windows and...." so it never reaches
    anything after that step until the lid is opened.

  • Gnome3: Cannot set laptop lid close action

    I've checked the lid closing sensor with watch /proc/acpi/button/lid/LID/state and the status changes without problems, but i can't set the lid closing action in gnome-tweak-tool or under power options. The laptop suspends only when an external monitor is not connected, i want to change it so it always suspends when the lid is closed.
    How can I fix this?
    Screenshots
    power options
    gnome-tweak-tool
    Last edited by klingt.net (2014-03-19 20:28:05)

    Seems to be a bug in gnome, gnome-tweak-tool outputs the following messages:
    INFO : GSettings missing key org.gnome.settings-daemon.plugins.power (key lid-close-battery-action)
    INFO : GSettings missing key org.gnome.settings-daemon.plugins.power (key lid-close-ac-action)
    INFO : GSettings missing key org.gnome.settings-daemon.plugins.power (key lid-close-suspend-with-external-monitor)
    I added the keys manually to the schema but gnome-tweak-tool show this error when i try to start it with the new keys:
    GLib-GIO-ERROR **: Settings schema 'org.gnome.settings-daemon.plugins.power' does not contain a key named 'lid-close-battery-action'
    There are more people having a similar problem.
    Last edited by klingt.net (2014-03-23 10:12:03)

  • OS X 10.8 Sleep on lid close with external monitor

    I have just upgradet to 10.8 Mountaiun Lion and i have noticed a strange bug.
    When I have attached my secondary monitor and i close the macbook it doesn't go to sleep.
    The laptop monitor is turn off, the main still remains working and no sleep.
    How can I sleep my MAC when i close the laptop with attached secondary monitor ?

    I have a comment and a question:
    Comment: I can connect to my Dell monitor that supports 1920x1080 using either DVI or HDMI and get the full resolutions of 1920x1080 no matter what (at least that is what Mountain Lion reports).  Any video I watch seems to be at just fine when viewed at a distance or up close.  Granted that the monitor is not 51" like yours, but still...
    Question:  For my own knowledge, how are you determining that you are seeing the video at a lower resolution?  I am curious because I don't notice this, and can't figure out how it could happen unless the source was 720p instead of 1080p.  Can you give me some pointers on how to check for this?

  • Disable automatic sleep on macbook lid close

    Is there ANY way to disable the macbook from going to sleep whenever I shut the lid? I'm very happy with my macbook overall, but the closing of the lid forcing it to sleep is making me not like that much more. Please help!!!

    Try this: http://www.macupdate.com/info.php/id/10564
    It really not a good idea to run the MacBook with the lid closed though, because the air is drawn in through the keyboard to cool the unit. With the lid closed, you could potentially overheat the MacBook.
    -Bmer
    Mac Owners Support Group - Join us @ MacOSG.com
      Mac611 Mobile Mac Support - about.Mac611.com
       iTunes:MacOSG Podcast | YouTube.MacOSG.com
                       An Apple User Group 
    Have an iPhone or iPod touch? Enter Mac611.com in Safari on it for 'mobile Mac support.'

  • Acpid no longer shutsdown on lid close

    Previous to some recent updates acpid and the event I had would shutdown my laptop when I closed the lid. It no longer works. I have acpid running always as a daemon.
    My /etc/acpi/handler.sh:
    #!/bin/sh
    # Default acpi script that takes an entry for all actions
    minspeed=`cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq`
    maxspeed=`cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq`
    setspeed="/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed"
    set $*
    case "$1" in
    button/power)
    #echo "PowerButton pressed!">/dev/tty5
    case "$2" in
    PBTN|PWRF) logger "PowerButton pressed: $2" ;;
    *) logger "ACPI action undefined: $2" ;;
    esac
    button/sleep)
    case "$2" in
    SLPB) echo -n mem >/sys/power/state ;;
    *) logger "ACPI action undefined: $2" ;;
    esac
    My /etc/acpi/events/lid file:
    event=button/lid (LID0)
    action= sudo /sbin/shutdown -h now
    Any ideas greatly appreciated.

    Easiest way I found to suspend the system to memory (to make it sleep) is by using /sys/power/state (this doesn't work with all the machines).
    $ cat /sys/power/state
    will tell you the supported modes and what you are looking for is "mem". For example "disk" will do a hibernation but to recover you need to modify boot time kernel options.
    If your system supports "mem" state, then all you need to do is
    $ echo -n mem >/sys/power/state
    and it should go to sleep, pressing power button or opening the lid should power it back on.
    Now if that worked fine you can script it into the /etc/acpi/handler.sh:
    button/lid)
    case "$3" in
    close)
    #echo "LID closed!">/dev/tty5
    echo -n mem >/sys/power/state
    open)
    #echo "LID opened!">/dev/tty5
    esac
    Note that we don't actually do anything on lid "open", since recovery is taken care by "BIOS".

  • ProBook 4710s - sound disabled after lid close

    Hello, I have a problem: When I connect headphones to the laptop, it works fine, until I close the lid. Then the sound stops working. I have tried to find it in Windows Control Panel (I have Windows 7), but there wasn't such an option. The sound is disabled only when it runs from battery; when I connect it to the electricity, I can use it with an external monitor and speakers and it works fine (even if the lid is closed). I have set "No action" after lid close, so the laptop doesn't go to sleep mode. It just stops playing sound.

    Hi,
    Download audio driver from here.
    Intructions how to install it in XP.
    Extract this driver with Winrar.
    Open Device manager and expand the Sound, video and game controllers section.
    Right click on Either the High Definition Audio Device if you have the generic Microsoft drivers, or the Conexant High Definition SmartAudio 221 if you have older Conexant drivers and choose "Update Driver Software..."
    Click Browse my computer for driver software, then click "Let me pick from a list of device drivers on my computer"
    Click "Have Disk..." then Browse to the folder where the drivers were extracted  .......\XP32 for 32-bit XP. Click OK.
    Select one of the "Conexant High Definition SmartAudio 221" models in the list, there will be multiple identical entries.
    Click Next, and you're done.
    I'm not sure which one from the list will work for You. On CQ60 few users confirmed then first one worked for them.
    ** Say thanks by clicking the "Thumb up" icon which is on the left. **
    ** Make it easier for other people to find solutions, by marking my answer with "Accept as Solution" if it solves your issue. **

  • Macbook air does not sleep after closing the lid or putting into sleep

    I've searched the message boards and external sites for answers and even spoke to Apple support.  I'm so frustrated because it affects my work everyday.  Its a 2013 Macbook Air running 10.9.2 and file vault.  I close the lid or force into sleep mode and the system stays on even though the display goes dark.  I travel alot so it goes into my briefcase and by morning its dead.  I have turned off bluetooth devices, reset the SMC, have no external devices connected other than a thunderbolt monitor, booted into safe mode and followed every suggestion out there.  Apple support person said he's never seen this before which is ridiculous because there are so many cases I have read about including Apple Support Communities.  Does anyone have any experience with this?

    This procedure is a diagnostic test. It makes no changes to your data.
    Please triple-click anywhere in the line below on this page to select it:
    pmset -g assertions | pbcopy
    Copy the selected text to the Clipboard by pressing the key combination command-C.
    Launch the built-in Terminal application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad. Click Utilities, then Terminal in the icon grid.
    Paste into the Terminal window by pressing the key combination command-V. I've tested these instructions only with the Safari web browser. If you use another browser, you may have to press the return key after pasting.
    Wait for a new line ending in a dollar sign ($) to appear below what you entered.
    The output of the command will be automatically copied to the Clipboard. If the command produced no output, the Clipboard will be empty. Paste into a reply to this message.
    The Terminal window doesn't show the output. Please don't copy anything from there.

  • The ACPI LID close event catched only 50% of the time.

    I'm using acpid with s2ram to have my laptop suspend to ram when I close the lid.
    This works fine... 50% of the time.
    Here is what happen:
    If the s2ram command is commented in my /etc/acpi/actions/lid.sh, and I run an acpi_listen in a terminal, I can see that each time I close or open the lid, the last number is incremented by 1:
    button/lid LID 00000080 00000001
    button/lid LID 00000080 00000002
    button/lid LID 00000080 00000003
    button/lid LID 00000080 00000004
    button/lid LID 00000080 00000005
    If the s2ram is NOT commented in my /etc/acpi/actions/lid.sh and I run acpi_listen in a terminal, here is what I see (we start the test with the lid opened):
    1) I close the lid. The acpi_listen shows:
    button/lid LID 00000080 00000001
    2) The s2ram is executed and the laptop suspends to ram. That is fine.
    3) I open the lid. The laptop resumes fine. Nothing happens in the acpi_listen output.
    4) The /proc/acpi/button/lid/LID/state shows "open"
    Here after is where the problem is:
    5) I close the lid. The acpi_listen DOES NOT SHOW ANYTHING :-(  => The /etc/acpi/actions/lid.sh will not be launched and the laptop will not be suspended
    6) The /proc/acpi/button/lid/LID/state shows "close"
    7) I open the lid. The acpi_listen shows:
    button/lid LID 00000080 00000002  => As one can see the last number is now 00000002 which shows that the acpid daemon never received anything for the second lid closure  :-(
    8) I close the lid. The acpi_listen shows:
    button/lid LID 00000080 00000003
    2) The s2ram is executed and the laptop suspends to ram. That is fine.
    So in fact it works the first time then I need to close/open/close the lid to have it suspend.
    Any idea ?
    Thanks in advance,

    Solved it by adding a file to /etc/pm/sleep.d/80-acpid with:
    #!/bin/sh
    case "$1" in
    hibernate|suspend)
    thaw|resume)
    /etc/rc.d/acpid restart
    *) exit $NA
    esac
    You have to call pm-suspend or hibernate followed by an ampersand (&) otherwise the acpid restart fails.
    EDIT: Sorry for the necro. Thought it was 2012. Either way I solved my problem with this so someone else might find it useful.
    Last edited by Revolt (2012-02-28 22:49:53)

  • Everytime I close my laptop, and then re-open it later, it automatically has logged me back into my account. Why is this?

    Hi,
    So, normally when I close my laptop after usage (putting it in sleep mode) it will automatically log it out of the account I am using. Whenever I want to go back into it, I have to type in my password before getting back in. However, every time I now open it, I don't have to type in any password; I am already logged into the account I was using before I had closed my laptop. Why is this happening? And how do I get this to stop?
    Any help would be appreciated!!
    -Thanks

    Some settings may have changed. Open System Preferences > Security & Privacy > General, and make sure that "Require password inmediately after sleep or screen saver begins" is ticked

Maybe you are looking for

  • I want to host user sites on Mac OS X Server 10.5.5

    Hi, Looking in httpd.conf I see the following:- #### For Mac OS X Server: Note that #### personal websharing is not supported on Mac OS X Server. Now, for 'compatibility' reasons I need to have two subsites that are fqdn/~sitename working on my serve

  • Data-source question

    Hi, I have defined a datasource in data-sources.xml file. If I do not specify the following parameters: max-connections min-connections then what are the default values the OC4J container takes? Secondly, on what basis are these values defined. I mea

  • PORDCH idoc outbound Delivery Completed Indicator

    Hi all, I am using PORDCH02 for sending PO changes. I have selected this IDoc due to I have to send the delivery completed indicator. I have to send PO changes when the delivery completed indicator has changed. But there are two situations when the i

  • Variable import from clipboard

    Hello experts, how can import values from clipboard for a variable screen in BEx 7.0? In BEx 3.x there was a button for this. Thanks in advance

  • Certificate erros and pages can't be opened

    My macbook keeps giving certificate errors. I can't open certain websites anymore (like Facebook). Help?