You are not logged in.

#1 2017-08-03 12:51:54

themissingcode
Member
Registered: 2016-08-21
Posts: 6

cinnamon-screensaver-command systemd service

Hi,

I want to lock my screen when I come out of sleep, my search came up to use systemd service to do that.

So I created the following service to do that:

[Unit]                               
Description=Lock Cinnamon X Session on sleep                               
Before=sleep.target                  

[Service]                            
Environment=DISPLAY=:0               
ExecStart=/usr/bin/cinnamon-screensaver-command --lock
ExecStartPost=/usr/bin/sleep 1

[Install]
WantedBy=sleep.target

But unfortunately this is not working. The service is enabled, but when I try it I get the following:

Aug 03 13:59:51 TTT-XX cinnamon-screensaver-command[25109]: Can't connect to screensaver!

I am not sure what am I doing wrong. I am suspecting that this will not work with cinnamon-screensaver-command because all examples I have seen uses something like slimlock or xlock, but I would really like to understand what is going on.

Offline

#2 2017-08-03 14:50:22

seth
Member
Registered: 2012-09-03
Posts: 51,229

Re: cinnamon-screensaver-command systemd service

dbus environment?
You could maybe adapt https://gist.githubusercontent.com/Alad … tfile1.txt

Offline

#3 2017-08-03 15:51:20

loqs
Member
Registered: 2014-03-06
Posts: 17,372

Re: cinnamon-screensaver-command systemd service

Looking at cinnamon-screensaver-command

$ cat /usr/bin/cinnamon-screensaver-command#!/bin/sh

exec /usr/share/cinnamon-screensaver/cinnamon-screensaver-command.py "$@"

Leads to the python script /usr/share/cinnamon-screensaver/cinnamon-screensaver-command.py

$ cat /usr/share/cinnamon-screensaver/cinnamon-screensaver-command.py 
#!/usr/bin/python3
....
from dbusdepot.screensaverClient import ScreenSaverClient
import config
....
class ScreensaverCommand:
    """
    This is a standalone executable that provides a simple way
    of controlling the screensaver via its dbus interface.
    """
    def __init__(self, mainloop):
        self.mainloop = mainloop
....
        self.client = ScreenSaverClient()
        self.client.connect("client-ready", self.on_client_ready)
....

Which derives its dbus support from /usr/share/cinnamon-screensaver/dbusdepot/screensaverClient.py

$ cat /usr/share/cinnamon-screensaver/dbusdepot/screensaverClient.py
....
class ScreenSaverClient(BaseClient):
    """
    This is the paired proxy paired to our ScreensaverService interface.

    It is only used by cinnamon-screensaver-command to communicate with
    the screensaver process.
    """
....
    def __init__(self):
        super(ScreenSaverClient, self).__init__(Gio.BusType.SESSION,
                                            CScreensaver.ScreenSaverProxy,
                                            c.SS_SERVICE,
                                            c.SS_PATH)
....

So you need to use the session bus of the session started by cinnamon-session which launches cinnamon-screensaver.
Please note "...." denotes sections of output removed for clarity

Offline

#4 2017-08-18 14:04:36

themissingcode
Member
Registered: 2016-08-21
Posts: 6

Re: cinnamon-screensaver-command systemd service

Thanks seth and loqs. Sorry for my delayed response, my knowledge in DBUS is limited and needed to look into it before posting about this any further.

The issue is resolved on its own though. I think maybe a restart was needed, which is probably weird?
For my knowledge the changes in systemd should be active once I enable them with --now option.

Offline

#5 2019-02-15 05:28:22

niknah
Member
Registered: 2019-02-15
Posts: 5

Re: cinnamon-screensaver-command systemd service

I had this problem too.  Fixed it up by adding to the .service file...

User=username
Environment=DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus

But change 1000 to your own userid, and "username" to your user name.

Offline

#6 2019-02-15 18:16:02

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: cinnamon-screensaver-command systemd service


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

Board footer

Powered by FluxBB