Nitrogen through systemd services doesn't work

216 Views Asked by At

I am writing a tool (zxcV32/OpenRWC) that fetches wallpapers from Reddit and sets them to the monitor(s) using nitrogen.

To make it easy to install and run automatically, I have created a deb package and a systemd service.

When the service is started using

sudo systemctl start openrwc@$USER.service

nitrogen errors out with exit status 1. (No other error message). And yes, the exec installed by the deb package works fine when manually run from the terminal.

I have compared that the command run by the tool is precisely the same when run through the systemd service or terminal run.

Sample command

nitrogen --set-scaled /home/zxcv32/.config/OpenRWC/fz41kmzk1wj91.jpg --head=0   

Service

[Unit]
Description=Reddit Wallpaper Changer for GNU/Linux
Requires=display-manager.service
After=display-manager.service
StartLimitIntervalSec=0

[Service]
Type=simple
ExecStart=/usr/bin/openrwc
Restart=always
RestartSec=5
User=%i

[Install]
WantedBy=graphical.target

What may be wrong with the service? I want the service to be the user's choice, if they want to run it or not.

BTW I found this question that claims that nitrogen works through a service. (maybe there is a difference between running nitrogen directly through system service and through a go funciton)

System: Debian 11 5.10.0-17-amd64

1

There are 1 best solutions below

0
zxcV32 On

Found the issue.

Systemd does not have access to certain environment variables.

DISPLAY environment variable needs to be set in the [email protected].

[Service]
Environment="DISPLAY=:0"