You are not logged in.

#1 2012-09-12 09:18:49

fixje
Member
From: Germany
Registered: 2010-02-13
Posts: 9

[SOLVED] xlock+suspend with systemd

I just switched from sysvinit to systemd on my ThinkPad X220 and tried to use most of its features. Thereby, I used its capability to handle sleep key events and suspend to RAM which beforehead has been done by acpid+pm. If I put my notebook to sleep I want xlock to be started. I don't care if that takes place before or after sleep mode is entered. I just want my notebook to be locked after wake up. For this purpose I had a hook in /etc/acpi/actions/sleep-button.sh:

...
export DISPLAY=:0
xhost +
su -c "DISPLAY=:0; xlock" fixje 2>> /tmp/udev.log &
#suspend
/usr/sbin/pm-suspend

Moving to systemd I created a hook in /usr/lib/systemd/system-sleep/lock-screen.sh

if [ "$1" = "pre" ]
then    
        export DISPLAY=:0
        xhost +
        su -c "DISPLAY=:0; xlock -mode blank -bg black -fg green" fixje >> /tmp/udev.log &
fi

Now the problems are as follows:

1. Using the hook stated above, my screen wents black after wakeup and xlock takes 100% of one CPU core. I have to login on a TTY and kill X sad

2. If I switched "pre" to "post" nothing happened at all. I don't even get any output in the log. I know the hook is executed, because I tested it with some "echo" statements.

P.S.: I'm using awesome wm, acpid is disabled and not running.

Any ideas?

Last edited by fixje (2012-09-12 20:48:37)

Offline

#2 2012-09-12 13:20:13

lahwaacz
Wiki Admin
From: Czech Republic
Registered: 2012-05-29
Posts: 748

Re: [SOLVED] xlock+suspend with systemd

Problem is, that scripts in /usr/lib/systemd/system-sleep/ must exit before the sleep process can continue. The alternative is to create xlock.service with the following (and run 'systemctl enable xlock.service of course):

[Install]
WantedBy=sleep.target

However, I've encountered some problems with xlock starting as daemon, so now I'm using slimlock with following slimlock.service:

[Unit]
Description=Lock X session using slimlock

[Service]
User=lahwaacz
ExecStart=/usr/bin/slimlock

[Install]
WantedBy=sleep.target

Offline

#3 2012-09-12 20:47:16

fixje
Member
From: Germany
Registered: 2010-02-13
Posts: 9

Re: [SOLVED] xlock+suspend with systemd

Thank you for the input, lahwaacz. I took your simlock.service and adjusted it to use xlock, which works like a charm.

[Unit]
Description=Lock X session using xlock

[Service]
User=fixje
Environment=DISPLAY=:0
ExecStart=/usr/bin/xlock -mode blank -bg black -fg green

[Install]
WantedBy=sleep.target

Creating a service seems to be the most elegant solution as you don't have to fiddle around in /usr/lib.

Offline

#4 2012-09-15 12:35:47

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

Re: [SOLVED] xlock+suspend with systemd

In case anyone's interested, the solution above also works with slock, for those of us who don't need all the bells and whistles that xlock provides. smile

Unfortunately, it doesn't work with i3lock, which I like because it lets me use an image for the lock screen, instead a solid colour.

Offline

#5 2012-09-15 14:51:09

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

Re: [SOLVED] xlock+suspend with systemd

tomk wrote:

In case anyone's interested, the solution above also works with slock, for those of us who don't need all the bells and whistles that xlock provides. smile

Unfortunately, it doesn't work with i3lock, which I like because it lets me use an image for the lock screen, instead a solid colour.

works fine for me... wink

[Unit]
Description=i3lock
Before=sleep.target

[Service]
User=<user>
Type=forking
Environment=DISPLAY=:0
ExecStart=/usr/bin/i3lock -c 000000

[Install]
WantedBy=sleep.target

Offline

#6 2012-09-15 15:09:04

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

Re: [SOLVED] xlock+suspend with systemd

oooh.... thanks, let's try that. Have to admit I've been trying to shortcut the learning curve here, by copy/pasting stuff before I know what it does. yikes

Yeah, that's awesome, working perfectly. Thanks 65kid.

Last edited by tomk (2012-09-15 15:20:32)

Offline

#7 2012-10-31 00:16:47

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

Re: [SOLVED] xlock+suspend with systemd

I use xtrlock and my service looks like this:

[Unit]
Description=Lock X session using xtrlock

[Service]
User=jakob
Environment=DISPLAY=:0
ExecStart=/usr/bin/xtrlock

[Install]
WantedBy=sleep.target

I wonder whether it would be wise to create a lock-session@.service and activate it via "systemctl enable lock-session@{xtrlock,slimlock,xlock}.service and have a line calling

ExecStart=/usr/bin/%i

Probably not, as some of the lockers seem to need arguments and one needs to adjust user & display variables as well…

Last edited by jakob (2012-10-31 00:17:02)

Offline

#8 2012-12-31 22:14:43

twistedcubic
Member
Registered: 2012-03-01
Posts: 22

Re: [SOLVED] xlock+suspend with systemd

Thanks for this!

Just to save a look to the wiki for some... this file should be created in /etc/systemd/system

Offline

#9 2013-01-24 20:31:37

browntown
Member
From: Salem, OR USA
Registered: 2012-11-20
Posts: 63

Re: [SOLVED] xlock+suspend with systemd

lahwaacz wrote:

slimlock with following slimlock.service:

[Unit]
Description=Lock X session using slimlock

[Service]
User=lahwaacz
ExecStart=/usr/bin/slimlock

[Install]
WantedBy=sleep.target

Perfect, THANK you.  Been messing with it for an hour. This should go in the wiki.

twistedcubic wrote:

this file should be created in /etc/systemd/system

Extra thanks, that was my first question.

Offline

Board footer

Powered by FluxBB