You are not logged in.

#1 2012-08-09 19:44:23

ninquitassar
Member
From: Italy
Registered: 2012-05-30
Posts: 29

[Solved] systemctl suspend and scripts

Bye! I switched from initscripts to systemd. So, systemd do not support pm-utils ad uses commands:

systemctl suspend
systemctl hibernate

for system suspension to disk and to ram.
I have a little problem, now. I used two scripts in /etc/pm/sleep.d/ for ALSA and for running slimlock.

90alsa

#!/bin/sh
#
# 90alsa: suspend/wakeup ALSA devices

case "$1" in
hibernate|suspend)
;;
thaw|resume)
aplay -d 1 /dev/zero
;;
*) exit $NA
;;
esac

00screensaver-lock

!/bin/sh
 #
 # 00screensaver-lock: lock workstation on hibernate or suspend
  
 username=ninquitassar # add your username here, i.e.: username=foobar

 USERHOME=/home/$username
 export XAUTHORITY="$USERHOME/.Xauthority"
 export DISPLAY=":0"
 
  case "$1" in
    hibernate|suspend)
       su $username -c "/usr/bin/slimlock" & # or any other such as /usr/bin/xscreensaver-command -lock
       ;;
    thaw|resume)
       ;;
    *) exit $NA
       ;;
 esac

So, in systemd wiki / Sleep Hooks is written that scripts in /usr/lib/systemd/system-sleep/ will executed pre and post suspension|hibernation with the following arguments:

$1 = "pre" | "post"
$2 = "suspend" | "hibernate"

So I thought that putting the scripts in /usr/lib/systemd/system-sleep/ may be a good idea. But I think that I must change them...
Changing in the two scripts

  case "$1" in
    hibernate|suspend)

with

  case "$1" in
    post)

can be useful?

Last edited by ninquitassar (2012-08-10 11:53:15)


CPU: AMD Sempron SI-42 - 2.1 Ghz  Video: Nvidia GeForce 8200MG  RAM: 4Gb DR
OS: Arch x86_64 + awesome + GTK+
My DeviantART

Offline

#2 2012-08-09 19:52:43

65kid
Member
From: Germany
Registered: 2011-01-26
Posts: 663

Re: [Solved] systemctl suspend and scripts

actually you should replace "hibernate|suspend" with "pre" (=before sleep) and not "post" (=after sleep). it should work fine then...

Offline

#3 2012-08-09 20:02:00

ninquitassar
Member
From: Italy
Registered: 2012-05-30
Posts: 29

Re: [Solved] systemctl suspend and scripts

Thank you. I will tell here if everything works.


CPU: AMD Sempron SI-42 - 2.1 Ghz  Video: Nvidia GeForce 8200MG  RAM: 4Gb DR
OS: Arch x86_64 + awesome + GTK+
My DeviantART

Offline

#4 2012-08-10 09:44:51

ninquitassar
Member
From: Italy
Registered: 2012-05-30
Posts: 29

Re: [Solved] systemctl suspend and scripts

Everything works... BUT when I close my laptop,the system runs suspension to run, then, when I open it, the system wakes up from suspension and re-runs suspension another time! hmm I use laptop mode tools, but I don't know if it can be related. How can I fix this behavior?


CPU: AMD Sempron SI-42 - 2.1 Ghz  Video: Nvidia GeForce 8200MG  RAM: 4Gb DR
OS: Arch x86_64 + awesome + GTK+
My DeviantART

Offline

#5 2012-08-10 09:51:32

65kid
Member
From: Germany
Registered: 2011-01-26
Posts: 663

Re: [Solved] systemctl suspend and scripts

I've never used laptop-mode-tools, so no idea what it does/how it works. How have you configured your laptop to go to sleep when closing the lid? power manager of your DE? acpid? Or more specifically, is it actually "systemctl suspend" that is called or is it "pm-suspend" or something from laptop-mode-tools?

Offline

#6 2012-08-10 10:55:49

ninquitassar
Member
From: Italy
Registered: 2012-05-30
Posts: 29

Re: [Solved] systemctl suspend and scripts

pm-utils don't works with systemd and events acpid related are handled by systemd.

https://wiki.archlinux.org/index.php/Sy … leep_hooks

Systemd does not use pm-utils to put the machine to sleep when using systemctl suspend or systemctl hibernate. Therefore all pm-utils hooks including any custom hooks you may have created will not be run. However, systemd provides a similiar mechanism to run custom scripts on these events. Systemd will run all executables in /usr/lib/systemd/system-sleep/ and pass two arguments to each of them:
argument 1: either pre or post, depending on whether the machine is going to sleep or waking up
argument 2: either suspend or hibernate, depending on what has been invoked
In contrast to pm-utils, systemd will run these scripts in parallel and not one after another.

https://wiki.archlinux.org/index.php/Sy … th_systemd

Systemd can handle some power-related ACPI events. This is configured via the following options in /etc/systemd/logind.conf:
HandlePowerKey : Power off the system when the power button is pressed
HandleSleepKey : Suspend the system when the sleep key is pressed
HandleLidSwitch : Suspend the system when the laptop lid is closed

Here is my /etc/systemd/logind.conf:

[Login]
#NAutoVTs=6
#KillUserProcesses=no
#KillOnlyUsers=
#KillExcludeUsers=root
#Controllers=
#ResetControllers=cpu
#InhibitDelayMaxSec=5
HandlePowerKey=any-session
HandleSleepKey=any-session
HandleLidSwitch=any-session

Before switching from initscripts to systemd I used pm-utils. In my system the package is still installed. If I try to remove it, pacman removes also some packages like k3b (and I need it!).

sudo pacman -Rsn pm-utils
Password: 
dependency control...

Packages (28): attica-0.4.0-1  grantlee-0.2.0-1  k3b-2.0.2-6  kactivities-4.9.0-1  kdebase-runtime-4.9.0-3  kdelibs-4.9.0-4  kdemultimedia-audiocd-kio-4.9.0-1
                libdbusmenu-qt-0.9.2-1  libiodbc-3.52.8-1  libkcddb-4.9.0-1  libkcompactdisc-4.9.0-1  libmusicbrainz5-5.0.1-1  libqzeitgeist-0.8.0-2  libssh-0.5.2-1
                media-player-info-17-1  nepomuk-core-4.9.0-1  oxygen-icons-4.9.0-1  phonon-1:4.6.0-2  phonon-gstreamer-4.6.1-1  pm-quirks-0.20100619-2
                polkit-qt-0.103.0-1  qca-2.0.3-2  redland-storage-virtuoso-1:1.0.15-3  shared-desktop-ontologies-0.10.0-1  soprano-2.8.0-2  strigi-0.7.7-2
                upower-0.9.17-2  pm-utils-1.4.1-5

Is it possible that the system runs both systemctl suspend and pm-suspend when I close the lid? In this case, how can I disable the pm-utils to handle this function?

I am sorry for the bad english, but I am italian

EDIT
I do not use any DE. I use awesome window manager.

Last edited by ninquitassar (2012-08-10 10:56:29)


CPU: AMD Sempron SI-42 - 2.1 Ghz  Video: Nvidia GeForce 8200MG  RAM: 4Gb DR
OS: Arch x86_64 + awesome + GTK+
My DeviantART

Offline

#7 2012-08-10 11:02:44

65kid
Member
From: Germany
Registered: 2011-01-26
Posts: 663

Re: [Solved] systemctl suspend and scripts

What DE are you using? As mentioned in the wiki, you shouldn't use systemd's acpi functionality together with Gnome/KDE/Xfce or whatever because they handle these events with their own power manager. I assume systemd suspends when you close the lid, but the power manager of your DE does the same, therefore two suspends.

and removing pm-utils and its dependencies should be fine. If you still need k3b, just reinstall it after that.

Offline

#8 2012-08-10 11:11:13

ninquitassar
Member
From: Italy
Registered: 2012-05-30
Posts: 29

Re: [Solved] systemctl suspend and scripts

ninquitassar wrote:

I do not use any DE. I use awesome window manager.

I will try to do this: smile

65kid wrote:

and removing pm-utils and its dependencies should be fine. If you still need k3b, just reinstall it after that.


CPU: AMD Sempron SI-42 - 2.1 Ghz  Video: Nvidia GeForce 8200MG  RAM: 4Gb DR
OS: Arch x86_64 + awesome + GTK+
My DeviantART

Offline

#9 2012-08-10 11:13:49

65kid
Member
From: Germany
Registered: 2011-01-26
Posts: 663

Re: [Solved] systemctl suspend and scripts

are you sure that you don't have acpid running? I have no idea what else could trigger the second suspend when you are just running awesome wm.

Offline

#10 2012-08-10 11:14:23

ninquitassar
Member
From: Italy
Registered: 2012-05-30
Posts: 29

Re: [Solved] systemctl suspend and scripts

k3b requires as a dependency pm-utils. hmm

EDIT

pacman -Qi pm-utils
...
Needed by  :  upower
pacman -Qi upower
...
Needed by  :  kdelibs
pacman -Qi kdelibs
...
Needed by  :  kactivities  libkcddb  nepomuk-core
pacman -Qi nepomuk-core
...
Needed by  :  kdebase-runtime
pacman -Qi kdebase-runtime
...
Needed by  :  k3b

Last edited by ninquitassar (2012-08-10 11:22:36)


CPU: AMD Sempron SI-42 - 2.1 Ghz  Video: Nvidia GeForce 8200MG  RAM: 4Gb DR
OS: Arch x86_64 + awesome + GTK+
My DeviantART

Offline

#11 2012-08-10 11:16:54

ninquitassar
Member
From: Italy
Registered: 2012-05-30
Posts: 29

Re: [Solved] systemctl suspend and scripts

65kid wrote:

are you sure that you don't have acpid running? I have no idea what else could trigger the second suspend when you are just running awesome wm.

in my system there is not initscripts installed, so I can't run a daemon, but only services. And the wiki says that systemd, with systemctl suspend, handles ACPI related events.


CPU: AMD Sempron SI-42 - 2.1 Ghz  Video: Nvidia GeForce 8200MG  RAM: 4Gb DR
OS: Arch x86_64 + awesome + GTK+
My DeviantART

Offline

#12 2012-08-10 11:19:49

65kid
Member
From: Germany
Registered: 2011-01-26
Posts: 663

Re: [Solved] systemctl suspend and scripts

ninquitassar wrote:
65kid wrote:

are you sure that you don't have acpid running? I have no idea what else could trigger the second suspend when you are just running awesome wm.

in my system there is not initscripts installed, so I can't run a daemon, but only services. And the wiki says that systemd, with systemctl suspend, handles ACPI related events.

that doesn't mean that you couldn't have enabled acpid.service . systemd may be able to handle these events, but you can just as well use acpid.service instead.

Offline

#13 2012-08-10 11:24:29

tomegun
Developer
From: France
Registered: 2010-05-28
Posts: 661

Re: [Solved] systemctl suspend and scripts

It could be that upower calls pm-utils. This should be sorted out in the next upower release which will prefer systemd if it is running.

Offline

#14 2012-08-10 11:28:04

65kid
Member
From: Germany
Registered: 2011-01-26
Posts: 663

Re: [Solved] systemctl suspend and scripts

tomegun wrote:

It could be that upower calls pm-utils. This should be sorted out in the next upower release which will prefer systemd if it is running.

does upower watch for ACPI events and trigger the suspend itself? I always thought the power managers of the DEs or acpid would watch for the ACPI events and then trigger upower which triggers pm-suspend!?

Offline

#15 2012-08-10 11:28:28

ninquitassar
Member
From: Italy
Registered: 2012-05-30
Posts: 29

Re: [Solved] systemctl suspend and scripts

You are right: I did not enable acpid.service, but systemd runs it.

systemctl status acpid.service
Password: 
acpid.service - ACPI event daemon
	  Loaded: loaded (/usr/lib/systemd/system/acpid.service; enabled)
	  Active: active (running) since Fri, 10 Aug 2012 10:10:52 +0200; 3h 12min ago
	Main PID: 295 (acpid)
	  CGroup: name=systemd:/system/acpid.service
		  └ 295 /usr/sbin/acpid -f

Aug 10 11:38:56 arch acpid[295]: client connected from 894[0:0]
Aug 10 11:38:56 arch acpid[295]: 1 client rule loaded
Aug 10 11:38:57 arch su[4176]: pam_unix(su:session): session closed for user ninquitassar
Aug 10 11:38:58 arch laptop-mode[6037]: Warning: Configuration file /etc/laptop-mode/conf.d/board-specific/*.conf is not readable, skipping.
Aug 10 11:38:58 arch laptop-mode[6061]: Laptop mode
Aug 10 11:38:58 arch laptop-mode[6062]: enabled, not active
Aug 10 11:38:59 arch laptop-mode[6378]: The configured LCD brightness command of the lcd-brightness module failed.
Aug 10 11:38:59 arch laptop-mode[6381]: Please check your configuration in /etc/laptop-mode/conf.d/lcd-brightness.conf.
Aug 10 11:39:00 arch laptop-mode[6389]: Command failed.
Aug 10 11:39:01 arch laptop-mode[6666]: Failed.

But in this case... why a double suspension? If acpid.service is a service of systemd, and systemd do not support pm-utils, why here there is a double suspension? Does pm-utils launch pm-suspend at lid closing? Where can I watch to fix this behavior?


CPU: AMD Sempron SI-42 - 2.1 Ghz  Video: Nvidia GeForce 8200MG  RAM: 4Gb DR
OS: Arch x86_64 + awesome + GTK+
My DeviantART

Offline

#16 2012-08-10 11:33:44

65kid
Member
From: Germany
Registered: 2011-01-26
Posts: 663

Re: [Solved] systemctl suspend and scripts

ninquitassar wrote:

But in this case... why a double suspension? If acpid.service is a service of systemd, and systemd do not support pm-utils, why here there is a double suspension? Does pm-utils launch pm-suspend at lid closing? Where can I watch to fix this behavior?

acpid watches for the events and calls /etc/acpi/handler.sh . But as far as I can see, it doesn't suspend the system on lid close by default.
pm-utils itself doesn't do anything on lid close, it is always invoked by other processes (like acpid or upower).
and it isn't like pm-utils isn't supported by systemd, it's just that systemd provides a (better) alternative.

just uninstall acpid and see if that fixes it.

Offline

#17 2012-08-10 11:40:12

ninquitassar
Member
From: Italy
Registered: 2012-05-30
Posts: 29

Re: [Solved] systemctl suspend and scripts

ha-ha! Here the problem:

/etc/acpi/handler.sh

button/lid)
    case $3 in
        close)
            #echo "LID switched!">/dev/tty5
	     /usr/sbin/pm-suspend &
	     DISPLAY=:0.0 su -c - ninquitassar /usr/bin/slimlock
            ;;

I will try to remove these lines.


CPU: AMD Sempron SI-42 - 2.1 Ghz  Video: Nvidia GeForce 8200MG  RAM: 4Gb DR
OS: Arch x86_64 + awesome + GTK+
My DeviantART

Offline

#18 2012-08-10 11:46:32

ninquitassar
Member
From: Italy
Registered: 2012-05-30
Posts: 29

Re: [Solved] systemctl suspend and scripts

It works!

button/lid)
    case $3 in
        close)
            #echo "LID switched!">/dev/tty5
	     #/usr/sbin/pm-suspend &
	     #DISPLAY=:0.0 su -c - ninquitassar /usr/bin/slimlock
            ;;

Thank you for the help! wink

EDIT
Changing the script, we can preserve screen lock with slimlock:

button/lid)
    case $3 in
        close)
            #echo "LID switched!">/dev/tty5
	     #/usr/sbin/pm-suspend &
	     DISPLAY=:0.0 su -c - username /usr/bin/slimlock
            ;;

Last edited by ninquitassar (2012-08-10 11:51:46)


CPU: AMD Sempron SI-42 - 2.1 Ghz  Video: Nvidia GeForce 8200MG  RAM: 4Gb DR
OS: Arch x86_64 + awesome + GTK+
My DeviantART

Offline

Board footer

Powered by FluxBB