You are not logged in.

#26 2012-12-03 22:44:06

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: Systemd suspend/resume service files

Where do you put these service files and are there any important name conventions to take care of?

Offline

#27 2012-12-04 00:09:48

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: Systemd suspend/resume service files

/etc/systemd/system, and no.

Offline

#28 2012-12-06 05:40:20

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: Systemd suspend/resume service files

So, I created the file /etc/systemd/system/wakeup.service:

[Unit]
Description=Run user script after suspend
After=suspend.target

[Service]
User=orschiro
Type=forking
Environment=DISPLAY=:0
ExecStart=/home/orschiro/.startup

[Install]
WantedBy=suspend.target

/home/orschiro/.startup

#!/bin/bash

# Reset keyboard options
setxkbmap -option ""
# Set layout
setxkbmap -layout "us,pl,de"
# Set international keyboard
setxkbmap -model "pc105"
# Use alt-shift to switch layout
setxkbmap -option "grp:alt_shift_toggle"

Then I started the service with systemctl start. After suspension the service seems to be not invoked. No error in journalctl. I already tried simple and oneshot instead of forking.

Offline

#29 2012-12-06 06:33:24

firecat53
Member
From: Lake Stevens, WA, USA
Registered: 2007-05-14
Posts: 1,542
Website

Re: Systemd suspend/resume service files

1. Do you see your unit file Description block in journalctl? like "Starting Run user script after suspend...."?
2. Is your .startup script executable?

Offline

#30 2012-12-06 20:18:53

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: Systemd suspend/resume service files

1. Nothing like that in journalctl.
2. Yes, it is. Does the service file have to be executable?

Any ideas what else I can try?

Last edited by orschiro (2012-12-06 20:20:35)

Offline

#31 2012-12-06 20:31:56

firecat53
Member
From: Lake Stevens, WA, USA
Registered: 2007-05-14
Posts: 1,542
Website

Re: Systemd suspend/resume service files

I'm not sure why your script isn't running...maybe add a command in .startup to echo a value into a text file to see if it's actually running or not. Perhaps the DISPLAY is wrong? No, the service file doesn't have to be executable.

Maybe try something like this :

....
[Service]
User=orschiro
Environment=DISPLAY=:0
Type=simple
ExecStartPre=/usr/bin/setxkbmap -option ""
ExecStartPre=/usr/bin/setxkbmap -layout "us,pl,de"
ExecStartPre=/usr/bin/setxkbmap -model "pc105"
ExecStart=/usr/bin/setxkbmap -option "grp:alt_shift_toggle"
.....

Scott

Last edited by firecat53 (2012-12-06 20:33:34)

Offline

#32 2012-12-06 21:14:00

vostok4
Member
Registered: 2010-12-16
Posts: 70

Re: Systemd suspend/resume service files

Seems to be the exact same thing I had, the service file just doesn't get executed, I gave up and used the shell scripts.

Offline

#33 2012-12-06 22:03:28

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: Systemd suspend/resume service files

[Unit]
Description=Run user script after suspend
After=suspend.target

[Service]
User=orschiro
Environment=DISPLAY=:0
Type=simple
ExecStartPre=/usr/bin/setxkbmap -option ""
ExecStartPre=/usr/bin/setxkbmap -layout "us,pl,de"
ExecStartPre=/usr/bin/setxkbmap -model "pc105"
ExecStart=/usr/bin/setxkbmap -option "grp:alt_shift_toggle"

[Install]
WantedBy=suspend.target
[orschiro@thinkpad ~]$ sudo stat /etc/systemd/system/wakeup-from-suspension.service 
  File: ‘/etc/systemd/system/wakeup-from-suspension.service’
  Size: 366       	Blocks: 8          IO Block: 4096   regular file
Device: fe00h/65024d	Inode: 391585      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2012-12-06 22:51:23.860226905 +0100
Modify: 2012-12-06 23:01:06.329260944 +0100
Change: 2012-12-06 23:01:06.329260944 +0100
 Birth: -
 Birth: -
[orschiro@thinkpad ~]$ journalctl 
-- Logs begin at Sa, 2012-11-10 23:14:05 CET, end at Do, 2012-12-06 23:02:17 CET. --
Nov 10 23:14:05 thinkpad systemd-journal[126]: Allowing runtime journal files to grow to 394.3M.
Nov 10 23:14:05 thinkpad kernel: Initializing cgroup subsys cpuset
Nov 10 23:14:05 thinkpad kernel: Initializing cgroup subsys cpu
Nov 10 23:14:05 thinkpad kernel: Linux version 3.6.6-1-ARCH (tobias@T-POWA-LX) (gcc version 4.7.2 (GCC) ) #1 SMP PREEMPT Mon Nov 5 11:57:22 CET 2012
Nov 10 23:14:05 thinkpad kernel: Command line: BOOT_IMAGE=/boot/vmlinuz-linux root=/dev/mapper/VolGroup00-Arch ro quiet
Nov 10 23:14:05 thinkpad kernel: Disabled fast string operations
Nov 10 23:14:05 thinkpad kernel: e820: BIOS-provided physical RAM map:
Nov 10 23:14:05 thinkpad kernel: BIOS-e820: [mem 0x0000000000000000-0x000000000009ebff] usable
Nov 10 23:14:05 thinkpad kernel: BIOS-e820: [mem 0x000000000009ec00-0x000000000009ffff] reserved
Nov 10 23:14:05 thinkpad kernel: BIOS-e820: [mem 0x00000000000dc000-0x00000000000fffff] reserved
Nov 10 23:14:05 thinkpad kernel: BIOS-e820: [mem 0x0000000000100000-0x00000000bd6a0fff] usable
Nov 10 23:14:05 thinkpad kernel: BIOS-e820: [mem 0x00000000bd6a1000-0x00000000bd6a6fff] reserved
Nov 10 23:14:05 thinkpad kernel: BIOS-e820: [mem 0x00000000bd6a7000-0x00000000bd7b6fff] usable
Nov 10 23:14:05 thinkpad kernel: BIOS-e820: [mem 0x00000000bd7b7000-0x00000000bd80efff] reserved
Nov 10 23:14:05 thinkpad kernel: BIOS-e820: [mem 0x00000000bd80f000-0x00000000bd8c6fff] usable
Nov 10 23:14:05 thinkpad kernel: BIOS-e820: [mem 0x00000000bd8c7000-0x00000000bd8d1fff] ACPI NVS
Nov 10 23:14:05 thinkpad kernel: BIOS-e820: [mem 0x00000000bd8d2000-0x00000000bd8d4fff] ACPI data
Nov 10 23:14:05 thinkpad kernel: BIOS-e820: [mem 0x00000000bd8d5000-0x00000000bd8d8fff] reserved
Nov 10 23:14:05 thinkpad kernel: BIOS-e820: [mem 0x00000000bd8d9000-0x00000000bd8dcfff] ACPI NVS
Nov 10 23:14:05 thinkpad kernel: BIOS-e820: [mem 0x00000000bd8dd000-0x00000000bd8dffff] reserved
Nov 10 23:14:05 thinkpad kernel: BIOS-e820: [mem 0x00000000bd8e0000-0x00000000bd906fff] ACPI NVS
Nov 10 23:14:05 thinkpad kernel: BIOS-e820: [mem 0x00000000bd907000-0x00000000bd907fff] ACPI data
Nov 10 23:14:05 thinkpad kernel: BIOS-e820: [mem 0x00000000bd908000-0x00000000bdb0efff] reserved
Nov 10 23:14:05 thinkpad kernel: BIOS-e820: [mem 0x00000000bdb0f000-0x00000000bdb9efff] ACPI NVS
Nov 10 23:14:05 thinkpad kernel: BIOS-e820: [mem 0x00000000bdb9f000-0x00000000bdbfefff] ACPI data
Nov 10 23:14:05 thinkpad kernel: BIOS-e820: [mem 0x00000000bdbff000-0x00000000bdbfffff] usable
Nov 10 23:14:05 thinkpad kernel: BIOS-e820: [mem 0x00000000bdc00000-0x00000000bfffffff] reserved
Nov 10 23:14:05 thinkpad kernel: BIOS-e820: [mem 0x00000000e0000000-0x00000000efffffff] reserved
Nov 10 23:14:05 thinkpad kernel: BIOS-e820: [mem 0x00000000fec00000-0x00000000fec0ffff] reserved
Nov 10 23:14:05 thinkpad kernel: BIOS-e820: [mem 0x00000000fed00000-0x00000000fed003ff] reserved
Nov 10 23:14:05 thinkpad kernel: BIOS-e820: [mem 0x00000000fed10000-0x00000000fed13fff] reserved
Nov 10 23:14:05 thinkpad kernel: BIOS-e820: [mem 0x00000000fed18000-0x00000000fed19fff] reserved
Nov 10 23:14:05 thinkpad kernel: BIOS-e820: [mem 0x00000000fed1c000-0x00000000fed8ffff] reserved
Nov 10 23:14:05 thinkpad kernel: BIOS-e820: [mem 0x00000000fee00000-0x00000000fee00fff] reserved
Nov 10 23:14:05 thinkpad kernel: BIOS-e820: [mem 0x00000000ff800000-0x00000000ffffffff] reserved
Nov 10 23:14:05 thinkpad kernel: BIOS-e820: [mem 0x0000000100000000-0x000000023bffffff] usable
Nov 10 23:14:05 thinkpad kernel: NX (Execute Disable) protection: active
Nov 10 23:14:05 thinkpad kernel: DMI present.
Nov 10 23:14:05 thinkpad kernel: DMI: LENOVO 7450AC7/7450AC7, BIOS 7WET70WW (3.20 ) 12/13/2011
Nov 10 23:14:05 thinkpad kernel: e820: update [mem 0x00000000-0x0000ffff] usable ==> reserved
Nov 10 23:14:05 thinkpad kernel: e820: remove [mem 0x000a0000-0x000fffff] usable
Nov 10 23:14:05 thinkpad kernel: No AGP bridge found
Nov 10 23:14:05 thinkpad kernel: e820: last_pfn = 0x23c000 max_arch_pfn = 0x400000000
Nov 10 23:14:05 thinkpad kernel: MTRR default type: uncachable
Nov 10 23:14:05 thinkpad kernel: MTRR fixed ranges enabled:
:

No luck. So how come that it works on some systems and on others not?

Offline

#34 2012-12-06 23:06:37

root
Member
From: 127.0.0.1
Registered: 2012-04-13
Posts: 297

Re: Systemd suspend/resume service files

What does the status of your service file tells you?

Does the same happen if you, instead of suspending, hibernate (create a copy of your file that points to hibernate.target)?

Last edited by root (2012-12-06 23:07:37)


\(o_X)/
                        'Cause I wanna be an Archy - An Archy in the UK // Sex Pistols

Offline

#35 2012-12-07 06:01:56

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: Systemd suspend/resume service files

Hmm that's interesting:

[orschiro@thinkpad ~]$ systemctl list-unit-files
...
wakeup-from-suspension.service              disabled
...

And it cannot be enabled through systemctl start wakeup-from-suspension.service

Another one:

[orschiro@thinkpad ~]$ systemctl show wakeup-from-suspesion.service
Id=wakeup-from-suspesion.service
Names=wakeup-from-suspesion.service
Description=wakeup-from-suspesion.service
LoadState=error
ActiveState=inactive
SubState=dead
InactiveExitTimestampMonotonic=0
ActiveEnterTimestampMonotonic=0
ActiveExitTimestampMonotonic=0
InactiveEnterTimestampMonotonic=0
CanStart=yes
CanStop=yes
CanReload=no
CanIsolate=no
StopWhenUnneeded=no
RefuseManualStart=no
RefuseManualStop=no
AllowIsolate=no
DefaultDependencies=yes
OnFailureIsolate=no
IgnoreOnIsolate=no
IgnoreOnSnapshot=no
NeedDaemonReload=no
JobTimeoutUSec=0
ConditionTimestampMonotonic=0
ConditionResult=no
LoadError=org.freedesktop.DBus.Error.FileNotFound "No such file or directory"
Restart=no
NotifyAccess=none
RestartUSec=100ms
TimeoutUSec=1min 30s
TimeoutStartUSec=1min 30s
TimeoutStopUSec=1min 30s
WatchdogUSec=0
WatchdogTimestampMonotonic=0
StartLimitInterval=10000000
StartLimitBurst=5
StartLimitAction=none
PermissionsStartOnly=no
RootDirectoryStartOnly=no
RemainAfterExit=no
GuessMainPID=yes
MainPID=0
ControlPID=0
Result=success
UMask=0022
LimitCPU=18446744073709551615
LimitFSIZE=18446744073709551615
LimitDATA=18446744073709551615
LimitSTACK=18446744073709551615
LimitCORE=18446744073709551615
LimitRSS=18446744073709551615
LimitNOFILE=65536
LimitAS=18446744073709551615
LimitNPROC=63039
LimitMEMLOCK=65536
LimitLOCKS=18446744073709551615
LimitSIGPENDING=63039
LimitMSGQUEUE=819200
LimitNICE=0
LimitRTPRIO=0
LimitRTTIME=18446744073709551615
OOMScoreAdjust=0
Nice=0
IOScheduling=0
CPUSchedulingPolicy=0
CPUSchedulingPriority=0
TimerSlackNSec=50000
CPUSchedulingResetOnFork=no
NonBlocking=no
StandardInput=null
StandardOutput=inherit
StandardError=inherit
TTYReset=no
TTYVHangup=no
TTYVTDisallocate=no
SyslogPriority=30
SyslogLevelPrefix=yes
SecureBits=0
CapabilityBoundingSet=18446744073709551615
MountFlags=0
PrivateTmp=no
PrivateNetwork=no
SameProcessGroup=no
ControlGroupModify=no
ControlGroupPersistent=no
IgnoreSIGPIPE=yes
NoNewPrivileges=no
KillMode=control-group
KillSignal=15
SendSIGKILL=yes
ExecMainStartTimestampMonotonic=0
ExecMainExitTimestampMonotonic=0
ExecMainPID=0
ExecMainCode=0
ExecMainStatus=0

What about the dbus error?

Last edited by orschiro (2012-12-07 06:08:40)

Offline

#36 2012-12-07 16:44:47

jakob
Member
From: Berlin
Registered: 2005-10-27
Posts: 419

Re: Systemd suspend/resume service files

orschiro wrote:

Hmm that's interesting:

[orschiro@thinkpad ~]$ systemctl list-unit-files
...
wakeup-from-suspension.service              disabled
...

And it cannot be enabled through systemctl start wakeup-from-suspension.service

AFAIK, enabling a service is done by $ systemctl enable <servicename>

Offline

#37 2012-12-07 20:21:58

root
Member
From: 127.0.0.1
Registered: 2012-04-13
Posts: 297

Re: Systemd suspend/resume service files

Just as jakob states in order for a service to be persistent (running with each startup) it has to be enabled and not only started.


\(o_X)/
                        'Cause I wanna be an Archy - An Archy in the UK // Sex Pistols

Offline

#38 2012-12-08 00:34:17

R00KIE
Forum Fellow
From: Between a computer and a chair
Registered: 2008-09-14
Posts: 4,734

Re: Systemd suspend/resume service files

Would something like this be ok for something that should run when the system boots (preferably quite early) and after suspend/hibernate?

[Unit]
Description=Test Unit
After=basic.target
After=suspend.target
After=hibernate.target

[Service]
Type=oneshot
ExecStart=/usr/bin/touch /test_unit

[Install]
WantedBy=basic.target
WantedBy=suspend.target
WantedBy=hibernate.target

Last edited by R00KIE (2012-12-08 00:34:40)


R00KIE
Tm90aGluZyB0byBzZWUgaGVyZSwgbW92ZSBhbG9uZy4K

Offline

#39 2012-12-08 08:57:02

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: Systemd suspend/resume service files

Thanks rookie,

/etc/systemd/system/autostart-boot-resume.service

[Unit]
Description=Run custom user autostart script located in ~/ on boot and resume from suspension and hibernation
After=basic.target
After=suspend.target
After=hibernate.target

[Service]
Type=oneshot
ExecStart=/home/orschiro/.autostart

[Install]
WantedBy=basic.target
WantedBy=suspend.target
WantedBy=hibernate.target
[orschiro@thinkpad ~]$ sudo systemctl enable autostart-boot-resume.service
ln -s '/etc/systemd/system/autostart-boot-resume.service' '/etc/systemd/system/basic.target.wants/autostart-boot-resume.service'
ln -s '/etc/systemd/system/autostart-boot-resume.service' '/etc/systemd/system/suspend.target.wants/autostart-boot-resume.service'
ln -s '/etc/systemd/system/autostart-boot-resume.service' '/etc/systemd/system/hibernate.target.wants/autostart-boot-resume.service'

But still the script is not run as indicated by missing echo in journalctl which I added to .autostart.

I am running out of ideas...

Offline

#40 2012-12-08 11:39:59

R00KIE
Forum Fellow
From: Between a computer and a chair
Registered: 2008-09-14
Posts: 4,734

Re: Systemd suspend/resume service files

I have a service (1) I want to convert to using systemd units and I have been doing some tests only with touch and it seems it is working reliably, you probably don't need the basic target if all you want is to run something after suspend/hibernate.

Since this thread is going on about running things after suspend/hibernate I was more asking for comments on if it was ok to do what I posted before. Also there is another target that should probably be included, it is hybrid-sleep.target but I haven't tested yet if it is really needed.

(1) The service I plan to convert is systemd-hddapm which is in the aur, at first I just dropped a script in /usr/lib/systemd/system-sleep since it was the quick and dirty way of doing it.


R00KIE
Tm90aGluZyB0byBzZWUgaGVyZSwgbW92ZSBhbG9uZy4K

Offline

#41 2012-12-08 21:45:56

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: Systemd suspend/resume service files

I finally got it working!

/home/orschiro/.autostart

#!/bin/bash

echo "Running .autostart now..."

# Reset keyboard options
setxkbmap -option ""
# Set layout
setxkbmap -layout "us,pl,de"
# Set international keyboard
setxkbmap -model "pc105"
# Use alt-shift to switch layout
setxkbmap -option "grp:alt_shift_toggle"
/etc/systemd/system/autostart-boot-resume.service 

[Unit]
Description=Run custom user autostart script located in ~/ on boot and resume from suspension and hibernation
After=basic.target
After=suspend.target
After=hibernate.target

[Service]
User=orschiro
Environment=DISPLAY=:0
ExecStartPre=/usr/bin/sleep 60
ExecStart=/home/orschiro/.autostart

[Install]
WantedBy=basic.target
WantedBy=suspend.target
WantedBy=hibernate.target

The problem was that .autostart was running well all the time but its settings were overwritten again by Gnome. Now using sleep and waiting 60 sec before .autostart gets executed does the trick.

Remember to start your custom service with $ systemctl start servicename.service

Thanks to all of you.

One last question. Is there a target that reacts on AC changes?

Robert

Last edited by orschiro (2012-12-08 22:10:08)

Offline

#42 2012-12-09 13:03:24

jakob
Member
From: Berlin
Registered: 2005-10-27
Posts: 419

Re: Systemd suspend/resume service files

No, but the powersave and powerdown scripts (see the packages on aur) have udev-rules that activate those scripts…

Offline

#43 2012-12-09 13:07:19

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: Systemd suspend/resume service files

Which themselves depend on pm-utils. That's what I wanted to know whether I can get rid of pm-utils.

Offline

#44 2012-12-09 13:24:30

jakob
Member
From: Berlin
Registered: 2005-10-27
Posts: 419

Re: Systemd suspend/resume service files

I see. pm-utils isn't needed for the udev rule, if you just incorporate that in your config

Offline

#45 2012-12-11 07:07:58

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: Systemd suspend/resume service files

Is it still needed for suspension or hibernation or is this also accomplished through systemd?

Offline

#46 2012-12-11 17:52:49

jakob
Member
From: Berlin
Registered: 2005-10-27
Posts: 419

Re: Systemd suspend/resume service files

orschiro wrote:

Is it still needed for suspension or hibernation or is this also accomplished through systemd?

Can't tell you where, but somewhere on the systemd mailing list it was said that pm-utils can safely be considered obsolete and of no use anymore when hibernating with systemd…

Offline

#47 2012-12-13 00:52:41

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: Systemd suspend/resume service files

I doubt it can be safely removed.

[orschiro@thinkpad ~]$ sudo pacman -Rscn pm-utils
checking dependencies...

Targets (34): alsa-plugins-1.0.26-1  caribou-0.4.4.2-1  cinnamon-1:1.6.7-3  cinnamon-applet-windows-preview-2.0.1-1  cinnamon-theme-minty-arch-1.0-1
              cups-pk-helper-0.2.4-1  ethtool-1:3.6-1  gjs-1.34.0-1  gnome-control-center-3.6.3-3  gnome-session-3.6.2-1  gnome-settings-daemon-3.6.3-2
              hdparm-9.43-1  libcanberra-pulse-0.30-3  libimobiledevice-1.1.4-2  libplist-1.8-2  libpwquality-1.2.0-1  libsocialweb-0.25.21-1  libwacom-0.6-1
              notification-daemon-0.7.6-1  pm-quirks-0.20100619-2  pulseaudio-2.1-1  pulseaudio-alsa-2-1  python-dbus-common-1.1.1-2  python2-atspi-2.6.0-2
              python2-dbus-1.1.1-2  python2-imaging-1.1.7-5  python2-lxml-3.0.1-1  rfkill-0.4-6  rtkit-0.11-1  tlp-0.3.7.1-1  upower-0.9.18-2
              usbmuxd-1.0.8-1  webrtc-audio-processing-0.1-1  pm-utils-1.4.1-5

Total Removed Size:     53,54 MiB

Do you want to remove these packages? [Y/n] n

Offline

#48 2012-12-13 00:59:31

Scimmia
Fellow
Registered: 2012-09-01
Posts: 11,466

Re: Systemd suspend/resume service files

A lot of things depend on upower. Right now, upower uses pm-utils to determine whether the kernel is capable of suspending/hibernating/etc. On a systemd system, that's all upower uses pm-utils, so if someone figures out a different way to determine that, submit a patch and maybe we can ditch pm-utils.

Offline

#49 2012-12-13 01:21:09

firecat53
Member
From: Lake Stevens, WA, USA
Registered: 2007-05-14
Posts: 1,542
Website

Re: Systemd suspend/resume service files

FWIW:  I'm using monsterwm and I removed pm-utils and successfully suspended to RAM and hibernated to disk without pm-utils (using systemctl {suspend,hibernate} ). The only package on my system that requires pm-utils is hal (which I only keep around for when I want to stream Amazon instant videos).

Scott

Last edited by firecat53 (2012-12-13 01:21:36)

Offline

#50 2012-12-13 06:10:59

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: Systemd suspend/resume service files

Thanks for telling Scott. I may try out to remove pm-utils here on Cinnamon.

Just for curiosity a slightly off-topic question: Is it possible to detect resume on hibernation and suspension with an udev rule?

Robert

EDIT:

I removed pm-utils resulting in no longer having a hibernate and suspend option in the shutdown menu of Cinnamon.

Last edited by orschiro (2012-12-24 10:09:45)

Offline

Board footer

Powered by FluxBB