You are not logged in.
I figured I'd try writing a .service file for redshift, however redshift fails to run when started this way (works perfectly when run from terminal).
glindste@arch-laptop ~>sudo systemctl status redshift.service
redshift.service - Redshift
Loaded: loaded (/etc/systemd/system/redshift.service; disabled)
Active: failed (Result: exit-code) since Fri 2014-02-21 19:29:11 CET; 2s ago
Process: 11885 ExecStart=/usr/bin/redshift -l 59.4:18.0 (code=exited, status=1/FAILURE)
Main PID: 11885 (code=exited, status=1/FAILURE)
Feb 21 19:29:11 arch-laptop systemd[1]: Started Redshift.
Feb 21 19:29:11 arch-laptop redshift[11885]: `RANDR Query Version' returned error -1
Feb 21 19:29:11 arch-laptop redshift[11885]: Initialization of randr failed.
Feb 21 19:29:11 arch-laptop redshift[11885]: Trying next method...
Feb 21 19:29:11 arch-laptop redshift[11885]: X request failed: XOpenDisplay
Feb 21 19:29:11 arch-laptop redshift[11885]: Initialization of vidmode failed.
Feb 21 19:29:11 arch-laptop redshift[11885]: Trying next method...
Feb 21 19:29:11 arch-laptop redshift[11885]: No more methods to try.
Feb 21 19:29:11 arch-laptop systemd[1]: redshift.service: main process exited, code=exited, status=1/FAILURE
Feb 21 19:29:11 arch-laptop systemd[1]: Unit redshift.service entered failed state.
My .service file is very simple:
[Unit]
Description=Redshift
[Service]
Type=simple
ExecStart=/usr/bin/redshift -l 59.33:18.06
[Install]
WantedBy=graphical.target
Usually when I run redshift in a terminal it says that it is using randr. Redshift uses xcb to connect to X server and query the randr version, but somehow it is prevented from doing this. Is this systemd's fault? Could it be that it sandboxes redshift in some way so that it cannot reach the X server? Or does my .service file need something more?
Thanks in advance
Last edited by glindste (2014-02-21 20:32:11)
Offline
I think you need something like
Environment=DISPLAY=:0
in your service section.
see as an example https://github.com/daoo/dotfiles/blob/m … ft.service
Offline
Thanks! It wasn't enough to get it working but I changed it to run as user as well and now it works!
Offline
Hey glindste, any chance of your pasting to completed code, as well as where you put it? Cheers.
Offline
I put this into ~/.config/systemd/user/redshift.service:
[Unit]
Description=Redshift
[Service]
Environment=DISPLAY=:0
ExecStart=/usr/bin/redshift -l 59.33:18.06
which I run with 'systemd --user start redshift.service' (notice that there is no install target so in this state it can only be started manually)
I also have this int /etc/systemd/system/user@.service.d/environment.conf:
[Service]
Environment=DISPLAY=:0
Environment=XDG_RUNTIME_DIR=/run/user/%I SHELL=%s
I'm not entirely sure if all that was necessary (DISPLAY is set in both files, it's probably enough to set it in one of them), and there might be something else I did that I forgot.
Anyway, good luck!
Offline
Thanks mate, will have a go at it, though I'd really like to make it start on xorg startup... might just drop it into my .xinitrc instead.
Offline
Just so you know, the 'SHELL=%s' won't do anything anymore when part of a system service. This is apparently because it is not actually safe for PID1 to be making use of NSS. But it will still work if the service file is a user unit (systemd --user) or is part of a service that is run as the root user.
This also applies to %U (UID) and %h ($HOME).
Edit: BTW, this change was introduced as of systemd version 209.
Last edited by WonderWoofy (2014-03-13 07:01:38)
Offline
A little addition to this interesting topic: I just discovered that upstream added systemd (user) service files for redshift and redshift-gtk in the 1.9 release (from April 6).
See the upstream release changelog and the commit to the Arch package.
I haven't tried it yet but I guess it is functional :-)
Edit: Not functional, see post below.
Last edited by Neitsab (2014-05-21 00:27:02)
Offline
The provided service files are not functional here. There are two problems:
First one is that the two provided systemd user services stall on the same randr error as described above in the thread:
$ systemctl --user start redshift-gtk.service
$ systemctl --user status redshift-gtk.service
● redshift-gtk.service - Redshift display colour temperature adjustment
Loaded: loaded (/usr/lib/systemd/user/redshift-gtk.service; disabled)
Active: failed (Result: start-limit) since mer. 2014-05-21 00:20:49 CEST; 4min 31s ago
Docs: http://jonls.dk/redshift/
Process: 10989 ExecStart=/usr/bin/redshift (code=exited, status=1/FAILURE)
Main PID: 10989 (code=exited, status=1/FAILURE)
mai 21 00:20:49 arch-clevo systemd[1338]: Unit redshift-gtk.service entered failed state.
mai 21 00:20:49 arch-clevo systemd[1338]: redshift-gtk.service holdoff time over, scheduling restart.
mai 21 00:20:49 arch-clevo systemd[1338]: Stopping Redshift display colour temperature adjustment...
mai 21 00:20:49 arch-clevo systemd[1338]: Starting Redshift display colour temperature adjustment...
mai 21 00:20:49 arch-clevo systemd[1338]: redshift-gtk.service start request repeated too quickly, refusing to start.
mai 21 00:20:49 arch-clevo systemd[1338]: Failed to start Redshift display colour temperature adjustment.
mai 21 00:20:49 arch-clevo systemd[1338]: Unit redshift-gtk.service entered failed state.
$ journalctl -b --user-unit=redshift-gtk
-- Logs begin at ven. 2014-05-02 15:49:42 CEST, end at mer. 2014-05-21 01:59:06 CEST. --
mai 21 00:20:48 arch-clevo systemd[1338]: Starting Redshift display colour temperature adjustment...
mai 21 00:20:48 arch-clevo systemd[1338]: Started Redshift display colour temperature adjustment.
mai 21 00:20:48 arch-clevo redshift[10979]: `RANDR Query Version' returned error -1
mai 21 00:20:48 arch-clevo redshift[10979]: Initialization of randr failed.
mai 21 00:20:48 arch-clevo systemd[1338]: redshift-gtk.service: main process exited, code=exited, status=1/FAILURE
mai 21 00:20:48 arch-clevo systemd[1338]: Unit redshift-gtk.service entered failed state.
mai 21 00:20:48 arch-clevo systemd[1338]: redshift-gtk.service holdoff time over, scheduling restart.
mai 21 00:20:48 arch-clevo systemd[1338]: Stopping Redshift display colour temperature adjustment...
...(repeats four times)...
mai 21 00:20:49 arch-clevo systemd[1338]: Starting Redshift display colour temperature adjustment...
mai 21 00:20:49 arch-clevo systemd[1338]: redshift-gtk.service start request repeated too quickly, refusing to start.
mai 21 00:20:49 arch-clevo systemd[1338]: Failed to start Redshift display colour temperature adjustment.
mai 21 00:20:49 arch-clevo systemd[1338]: Unit redshift-gtk.service entered failed state.
(it is the same for /usr/lib/systemd/user/redshift.service)
Adding "Environment=DISPLAY=:0" to the service files as suggested by Neburski (under [Service], above ExecStart) and reloading user daemons ($ systemctl --user daemon-reload) do solve the problem.
However, another problem then arises specifically for redshift-gtk.service: the tray icon doesn't appear.
It took me some time to figure it out, but actually if you've been watchful you might have already spotted what causes this: the redshift-gtk.service provided by Arch contains the wrong binary name.
Instead of having "ExecStart=/usr/bin/redshift-gtk" it contains "ExecStart=/usr/bin/redshift", as can be seen in the first systemctl status. There is a discrepancy between upstream and the Arch package: upstream file (not updated since March 6) and Arch x86_64 package (download and browse the archive to /usr/lib/systemd/user/redshift-gtk.service).
Replacing the binary name (simply adding "-gtk") does correct the issue, the tray icon appears on service start.
After doing those two steps, here's the output of systemctl status:
$ systemctl --user status redshift-gtk.service
● redshift-gtk.service - Redshift display colour temperature adjustment
Loaded: loaded (/usr/lib/systemd/user/redshift-gtk.service; disabled)
Active: active (running) since mer. 2014-05-21 03:27:29 CEST; 17s ago
Docs: http://jonls.dk/redshift/
Main PID: 14493 (redshift-gtk)
CGroup: /user.slice/user-1000.slice/user@1000.service/redshift-gtk.service
├─14493 python3 /usr/bin/redshift-gtk
└─14494 /usr/bin/redshift -v
mai 21 03:27:29 arch-clevo systemd[1338]: Starting Redshift display colour temperature adjustment...
mai 21 03:27:29 arch-clevo systemd[1338]: Started Redshift display colour temperature adjustment.
Bug report is on its way...
Edit: FS#40476 (Arch bug tracker)
Edit 2: upstream bug report
Last edited by Neitsab (2014-05-21 01:33:50)
Offline
Create ~/.config/systemd/user/redshift.service.d/display.conf
Put the following in, replace DISPLAY value with whatever you actually need:
[Service]
Environment=DISPLAY=:0
Then do "systemctl --user start redshift" and enjoy. "systemctl --user enable redshift" if you want to run this on every login.
I'm very interested in finding a general solution for providing the active DISPLAY variable value to a systemd service, automatically. Running screenlocking has the exact same issue, for example.
Last edited by lkraav (2014-08-16 18:13:02)
Offline
This worked for me, changing the bin to redshift-gtk and enabling it changes the screen color on start. I'm not seeing the tray icon, however. Any ideas why?
Offline
Create ~/.config/systemd/user/redshift.service.d/display.conf
Put the following in, replace DISPLAY value with whatever you actually need:
[Service]
Environment=DISPLAY=:0Then do "systemctl --user start redshift" and enjoy. "systemctl --user enable redshift" if you want to run this on every login.
I'm very interested in finding a general solution for providing the active DISPLAY variable value to a systemd service, automatically. Running screenlocking has the exact same issue, for example.
I have used this method and still get the same error when I run 'systemctl --user start redshift":
Feb 18 19:36:11 socrates systemd[6255]: Started Redshift display colour temperature adjustment.
Feb 18 19:36:11 socrates redshift[7453]: No protocol specified
Feb 18 19:36:11 socrates redshift[7453]: `RANDR Query Version' returned error -1
Feb 18 19:36:11 socrates redshift[7453]: Initialization of randr failed.
Feb 18 19:36:11 socrates systemd[6255]: redshift.service: main process exited, code=exited, status=1/FAILURE
Feb 18 19:36:11 socrates systemd[6255]: Unit redshift.service entered failed state.
Feb 18 19:36:11 socrates systemd[6255]: redshift.service failed.
Feb 18 19:36:11 socrates systemd[6255]: redshift.service holdoff time over, scheduling restart.
Feb 18 19:36:11 socrates systemd[6255]: Stopping Redshift display colour temperature adjustment...
Feb 18 19:36:11 socrates systemd[6255]: Starting Redshift display colour temperature adjustment...
Feb 18 19:36:11 socrates systemd[6255]: start request repeated too quickly for redshift.service
Feb 18 19:36:11 socrates systemd[6255]: Failed to start Redshift display colour temperature adjustment.
Feb 18 19:36:11 socrates systemd[6255]: Unit redshift.service entered failed state.
Feb 18 19:36:11 socrates systemd[6255]: redshift.service failed.
Offline
You sure your DISPLAY is :0?
I find most annoying about gdm that it rotates DISPLAY numbers as some sort of a initialization failover mechanism. I would rather have it retry :0 until it can get to it, but there's no way to configure that.
Offline
Yes, my DISPLAY is :0. I have started redshift from the command line but it looks like the systemd redshift or redshift-gtk servcies give the same error.
Offline
I'm always able to start/restart the service manually, but the automatic start usually (maybe always now?) fails.
-- Reboot --
Feb 14 16:04:29 archdesk redshift[416]: `RANDR Query Version' returned error -1
Feb 14 16:04:29 archdesk redshift[418]: `RANDR Query Version' returned error -1
Feb 14 16:04:29 archdesk redshift[420]: `RANDR Query Version' returned error -1
Feb 14 16:04:30 archdesk redshift[422]: `RANDR Query Version' returned error -1
-- Reboot --
Feb 14 19:32:07 archdesk redshift[417]: `RANDR Query Version' returned error -1
Feb 14 19:32:07 archdesk redshift[419]: `RANDR Query Version' returned error -1
Feb 14 19:32:08 archdesk redshift[421]: `RANDR Query Version' returned error -1
-- Reboot --
Feb 14 23:10:10 archdesk redshift[414]: `RANDR Query Version' returned error -1
Feb 14 23:10:11 archdesk redshift[418]: `RANDR Query Version' returned error -1
-- Reboot --
Feb 15 14:09:20 archdesk redshift[415]: `RANDR Query Version' returned error -1
Feb 15 14:09:21 archdesk redshift[421]: `RANDR Query Version' returned error -1
-- Reboot --
Feb 15 21:30:04 archdesk redshift[411]: `RANDR Query Version' returned error -1
-- Reboot --
Feb 18 22:39:10 archdesk redshift[405]: `RANDR Query Version' returned error -1
Feb 18 22:39:10 archdesk redshift[407]: `RANDR Query Version' returned error -1
Feb 18 22:39:11 archdesk redshift[415]: `RANDR Query Version' returned error -1
-- Reboot --
Feb 19 19:46:36 archdesk redshift[413]: `RANDR Query Version' returned error -1
Feb 19 19:46:36 archdesk redshift[415]: `RANDR Query Version' returned error -1
-- Reboot --
Feb 20 00:59:52 archdesk redshift[408]: `RANDR Query Version' returned error -1
Feb 20 00:59:52 archdesk redshift[410]: `RANDR Query Version' returned error -1
-- Reboot --
Feb 20 15:28:15 archdesk redshift[412]: `RANDR Query Version' returned error -1
Feb 20 15:28:15 archdesk redshift[414]: `RANDR Query Version' returned error -1
Feb 20 15:28:15 archdesk redshift[438]: `RANDR Query Version' returned error -1
-- Reboot --
Feb 20 18:14:44 archdesk redshift[416]: `RANDR Query Version' returned error -1
Feb 20 18:14:45 archdesk redshift[418]: `RANDR Query Version' returned error -1
Feb 20 18:14:45 archdesk redshift[420]: `RANDR Query Version' returned error -1
-- Reboot --
Feb 21 19:47:27 archdesk redshift[417]: `RANDR Query Version' returned error -1
Feb 21 19:47:27 archdesk redshift[419]: `RANDR Query Version' returned error -1
Feb 21 19:47:28 archdesk redshift[421]: `RANDR Query Version' returned error -1
Feb 21 19:47:28 archdesk redshift[423]: `RANDR Query Version' returned error -1
-- Reboot --
Feb 23 22:22:16 archdesk redshift[1655]: `RANDR Query Version' returned error -1
Feb 23 22:22:17 archdesk redshift[1659]: `RANDR Query Version' returned error -1
Feb 23 22:22:17 archdesk redshift[1661]: `RANDR Query Version' returned error -1
-- Reboot --
Feb 24 20:28:46 archdesk redshift[437]: `RANDR Query Version' returned error -1
-- Reboot --
Feb 24 21:04:08 archdesk redshift[443]: `RANDR Query Version' returned error -1
Feb 24 21:04:08 archdesk redshift[445]: `RANDR Query Version' returned error -1
Feb 24 21:04:09 archdesk redshift[447]: `RANDR Query Version' returned error -1
Feb 24 21:04:09 archdesk redshift[449]: `RANDR Query Version' returned error -1
Here's my .service file:
[Unit]
Description=Redshift display colour temperature adjustment
Documentation=http://jonls.dk/redshift/
After=display-manager.service
[Service]
Environment=DISPLAY=:0
ExecStart=/usr/bin/redshift
Restart=always
[Install]
WantedBy=default.target
And my config file:
; Global settings for redshift
[redshift]
; Set the day and night screen temperatures
temp-day=5700
temp-night=4000
; Enable/Disable a smooth transition between day and night
; 0 will cause a direct change from day to night screen temperature.
; 1 will gradually increase or decrease the screen temperature
transition=1
; Set the screen brightness. Default is 1.0
;brightness=0.9
; It is also possible to use different settings for day and night since version 1.8.
;brightness-day=1.0
;brightness-night=0.8
; Set the screen gamma (for all colors, or each color channel individually)
;gamma=0.8
;gamma=0.8:0.7:0.8
; Set the location-provider: 'geoclue', 'gnome-clock', 'manual'
; type 'redshift -l list' to see possible values
; The location provider settings are in a different section.
location-provider=manual
; Set the adjustment-method: 'randr', 'vidmode'
; type 'redshift -m list' to see all possible values
; 'randr' is the preferred method, 'vidmode' is an older API
; but works in some cases when 'randr' does not.
; The adjustment method settings are in a different section.
adjustment-method=randr
; Configuration of the location-provider:
; type 'redshift -l PROVIDER:help' to see the settings
; ex: 'redshift -l manual:help'
[manual]
lat=42.4
lon=-83.3
; Configuration of the adjustment-method
; type 'redshift -m METHOD:help' to see the settings
; ex: 'redshift -m randr:help'
; In this example, randr is configured to adjust screen 1.
; Note that the numbering starts from 0, so this is actually the second screen.
[randr]
screen=0
Offline
I confirm this is not working for me. I actually managed to get this working on my desktop running archlinux following this post. But trying the same on my laptop just doesn't work. Still running into the same issue. Both systems are up2date and have same randr and redshift-minimal packages.
Mar 21 11:27:00 snupe redshift[1981]: No protocol specified
Mar 21 11:27:00 snupe redshift[1981]: `RANDR Query Version' returned error -1
Mar 21 11:27:00 snupe redshift[1981]: Initialization of randr failed.
I have Environment=DISPLAY=:0 in the service file and also in .config/systemd/user/redshift.service.d/display.conf
Offline
Redshift is working perfectly for me and I also have these errors every time I close my laptop and it suspends. I found no real consequences from them. Redshift continues to work.
You needed to edit your systemd .service file and add the correct DISPLAY value as it is described here:
https://wiki.archlinux.org/index.php/Sy … _variables
But you no longer have to. The cooperation between systemd and xorg-xerver has improved. Since I upgraded to xorg-server 1.17.1-3 and systemd 218 everything works out of the box, without the need to edit anything. Not sure which one exactly is the reason, maybe both. Anyway, just start the vanilla redshift.service as a _user_ service and it should work.
However, gdm from Gnome 3.16, the one that is currently in [testing], starts the default session on DISPLAY :1. If you edit /etc/systemd/user.conf like it is described in the link above and add the line 'DefaultEnvironment=DISPLAY=:1' - then again - all works without any additional tinkering.
My redshift.conf attached:
;default
temp-day=5500
;default
temp-night=3500transition=1
gamma=0.8
;default
location-provider=manualadjustment-method=randr
[manual]
lat=42.42
lon=23.20[randr]
crtc=0
Offline
xrandr startx with X. redshift service will retry after some time, you can set it to e.g. 30s so the log won't be full or these xrandr errors.
Offline
Thanks for the tip! I added this line to the [Service] section of /usr/lib/systemd/user/redshift.service: "RestartSec=10"
Now it autostarts correctly!
Offline
I suspect that this may also be a startup ordering issue, that X may simply not be properly started yet or similar. I found that creating a start script for redshift with a simple sleep 5 in it works (in addition to making sure the DISPLAY variable was set in a dropin). So
in ~/bin/start_redshift
#!/bin/bash
sleep 5
exec /usr/bin/redshift
in ~/.config/systemd/user/redshift.service
[Unit]
Description=Redshift - color temp adjustment.
[Service]
Type=simple
ExecStart=/home/$USER/bin/start_redshift
[Install]
WantedBy=default.target
and in .config/systemd/user/redshift.service.d/display.conf
[Service]
Environment=DISPLAY=:0
Offline
Hmm, still none of this worked for me on my laptop. Since I use KDE I managed to get it automatically started by using the Startup and Shutdown option in Settings. Works fine with that.
Offline
I also had to set the XAUTHORITY enviroment variable to get this service to work.
[Service]
Environment="DISPLAY=:0" "XAUTHORITY=/run/user/1000/gdm/Xauthority"
..
XAUTHORITY is probably some other path for you, check echo $XAUTHORITY. And I'm not running it as a user service..
Offline
I wanted to provide some feedback.
Putting the line "Environment=DISPLAY=:0" into the redshift.service file had NO effect.
Creating a new dir/file for ~/.config/systemd/user/redshift.service.d/display.conf did work.
So, I have a pristine, unmodified service file, and I just setup the environment variable and it started working.
Offline