1

I can run redshift from a command line, but can't get it working in systemd. The steps in a similar question didn't do the trick for me.

Ubuntu 16.04.

My redshift.service:

$ cat /etc/systemd/system/redshift.service 
[Unit]
Description=restrict blue light
After=graphical.target

[Service]
ExecStart=/usr/bin/redshift -v 
Environment=DISPLAY=:0

[Install]
WantedBy=graphical.target

If I run /usr/bin/redshift from the command line it starts recoloring my screen. If I try to start the service it dumps:

$ sudo systemctl status redshift
● redshift.service - restrict blue light
   Loaded: loaded (/etc/systemd/system/redshift.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Sun 2018-09-16 21:23:51 PDT; 4s ago
  Process: 4676 ExecStart=/usr/bin/redshift -v -l 37.35:121.99 (code=exited, status=1/FAILURE)
 Main PID: 4676 (code=exited, status=1/FAILURE)

Sep 16 21:23:51 cyberpower-linux redshift[4676]: Initialization of randr failed.
Sep 16 21:23:51 cyberpower-linux redshift[4676]: Trying next method...
Sep 16 21:23:51 cyberpower-linux redshift[4676]: No protocol specified
Sep 16 21:23:51 cyberpower-linux redshift[4676]: X request failed: XOpenDisplay
Sep 16 21:23:51 cyberpower-linux redshift[4676]: Initialization of vidmode failed.
Sep 16 21:23:51 cyberpower-linux redshift[4676]: Trying next method...
Sep 16 21:23:51 cyberpower-linux redshift[4676]: No more methods to try.
Sep 16 21:23:51 cyberpower-linux systemd[1]: redshift.service: Main process exited, code=exited, status=1/FAILURE
Sep 16 21:23:51 cyberpower-linux systemd[1]: redshift.service: Unit entered failed state.
Sep 16 21:23:51 cyberpower-linux systemd[1]: redshift.service: Failed with result 'exit-code'.

If I run xhost + and try to start again, it does start coloring the screen. How can I give my systemd script access to my window server without giving everything access to my window server?

Thanks in advance for any clues...

megabob
  • 11

2 Answers2

0

An update: after moving the service from /etc/systemd/system/redshift.service to ~/.config/systemd/user/redshift.servce, it started working.

Note that /etc/systemd/user/redshift.service didn't work!

I'd still welcome an answer showing me how to install this for all users of this host.

megabob
  • 11
0

Keep restarting it and it will finally work lol. The problem might be that, before logging in, gdm has not yet started Xorg and thus there is no display but I am not sure. I would try having gdm started first as a requirement and see what happens.

[Unit]

After=multi-user.target 

StartLimitIntervalSec=0

[Service]

Type=simple

ExecStart=/usr/bin/redshift -O 3000

Environment=DISPLAY=:0

Restart=always

RuntimeMaxSec=60

[Install]

WantedBy=graphical.target
tinlyx
  • 3,230
kostas
  • 1