You are not logged in.

#1 2015-02-20 08:59:13

AlexTes
Member
Registered: 2013-11-16
Posts: 10

feh failes to set a background from systemd unit

Per the wiki I have the following unit added to my systemd user instance.

[Unit]
Description=Random wallpaper with feh

[Service]
Type=oneshot
EnvironmentFile=%h/.config/wallpaper
ExecStart=/bin/bash -c '/usr/bin/feh --bg-fill "$(find ${WALLPATH} -type d \( -path ${WALLPATH}Mirrors\ Edge -o -path ${WALLPATH}Mass\ Effect\ 3 \) -prune -o -type f -print|shuf|head -n 1)"'

[Install]
WantedBy=default.target

The environment file looks like this.

WALLPATH=/home/alexander/Pictures/wallpapers/
#DISPLAY=:0

Adding the display line fixed the same issue before for me if I recall correctly, but apparently it no longer does.

Both with and without the display line the unit fails with the following status.

 $  systemctl --user status feh-wallpaper.service                                                                              ⏎
● feh-wallpaper.service - Random wallpaper with feh
   Loaded: loaded (/home/alexander/.config/systemd/user/feh-wallpaper.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Fri 2015-02-20 09:39:25 CET; 18s ago
  Process: 7754 ExecStart=/bin/bash -c /usr/bin/feh --bg-fill "$(find ${WALLPATH} -type d \( -path ${WALLPATH}Mirrors\ Edge -o -path ${WALLPATH}Mass\ Effect\ 3 \) -prune -o -type f -print|shuf|head -n 1)" (code=exited, status=2)
 Main PID: 7754 (code=exited, status=2)

Feb 20 09:39:25 alex-arch bash[7754]: shuf: write error: Broken pipe
Feb 20 09:39:25 alex-arch bash[7754]: feh ERROR: Can't open X display. It *is* running, yeah?
Feb 20 09:39:25 alex-arch systemd[2415]: feh-wallpaper.service: main process exited, code=exited, status=2/INVALIDARGUMENT
Feb 20 09:39:25 alex-arch systemd[2415]: Failed to start Random wallpaper with feh.
Feb 20 09:39:25 alex-arch systemd[2415]: Unit feh-wallpaper.service entered failed state.
Feb 20 09:39:25 alex-arch systemd[2415]: feh-wallpaper.service failed.

Did some testing.

/usr/bin/feh --bg-fill "$(find ${WALLPATH} -type d \( -path ${WALLPATH}Mirrors\ Edge -o -path ${WALLPATH}Mass\ Effect\ 3 \) -prune -o -type f -print|shuf|head -n 1)"

That works after setting WALLPATH. Looking at my environment variables DISPLAY=:0.

Bonus question: does it matter whether I run feh with bash opposed to zsh? (Shell is set to zsh)

Last edited by AlexTes (2015-02-20 09:07:39)

Offline

#2 2015-02-20 09:34:43

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: feh failes to set a background from systemd unit

AlexTes wrote:

Bonus question: does it matter whether I run feh with bash opposed to zsh? (Shell is set to zsh)

Only if you want to use some shell-specific features in that command string.

How are you making sure this starts after X? I'm guessing you simply aren't. Try manually restarting it once X is fully up and running.

Why not simply put this in .xinitrc (or similar)?

Offline

#3 2015-02-20 09:42:38

AlexTes
Member
Registered: 2013-11-16
Posts: 10

Re: feh failes to set a background from systemd unit

Thanks for answering my curiosity. I guess its down to performance then, but that matters little at this level.

I have tried restarting. The script always fails with the above error. I have also reloaded the systemd daemon after removing the DISPLAY line ;].

It's not in .xinitrc because there's a timer unit that runs the wallpaper setter after a given time has passed. I also thought it was a neat way to do things and learn to use systemd.

Offline

#4 2015-02-20 10:02:44

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: feh failes to set a background from systemd unit

AlexTes wrote:

I have tried restarting. The script always fails with the above error. I have also reloaded the systemd daemon after removing the DISPLAY line ;].

You definitely need DISPLAY. But with a simplified version of your .service file (Environment=DISPLAY=:0 and hardcoded img path) that is all it takes to make it work for me.

It might be nicer to set something up (with systemctl --user import-environment) to use your actually DISPLAY instead of hardcoding it to :0 and the release notes for systemd 219 mention the inclusion of a scriptlet to do just that.

Offline

#5 2015-02-20 12:48:51

AlexTes
Member
Registered: 2013-11-16
Posts: 10

Re: feh failes to set a background from systemd unit

New unit file:

[Unit]
Description=random wallpaper setter

[Service]
Type=oneshot
EnvironmentFile=%h/.config/wallpaper
Environment="DISPLAY=:0" "WALLPATH=/home/alexander/Pictures/wallpapers/"
ExecStart=/bin/bash -c '/usr/bin/feh --bg-fill "$(find /home/alexander/Pictures/wallpapers -type f -print|shuf|head -n 1)"'

[Install]
WantedBy=default.target

Doesn't work.

Even all cleaned up and like this, it still doesn't work.

[Unit]
Description=random wallpaper setter

[Service]
Type=oneshot
Environment=DISPLAY=:0
ExecStart=/bin/bash -c '/usr/bin/feh --bg-fill "$(find /home/alexander/Pictures/wallpapers -type f -print|shuf|head -n 1)"'

[Install]
WantedBy=default.target
● feh-wallpaper.service - random wallpaper setter
   Loaded: loaded (/home/alexander/.config/systemd/user/feh-wallpaper.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Fri 2015-02-20 13:38:11 CET; 6s ago
  Process: 19229 ExecStart=/bin/bash -c /usr/bin/feh --bg-fill "$(find /home/alexander/Pictures/wallpapers -type f -print|shuf|head -n 1)" (code=exited, status=2)
 Main PID: 19229 (code=exited, status=2)

Feb 20 13:38:11 alex-arch bash[19229]: shuf: write error: Broken pipe
Feb 20 13:38:11 alex-arch bash[19229]: shuf: write error
Feb 20 13:38:11 alex-arch bash[19229]: No protocol specified
Feb 20 13:38:11 alex-arch bash[19229]: feh ERROR: Can't open X display. It *is* running, yeah?
Feb 20 13:38:11 alex-arch systemd[995]: feh-wallpaper.service: main process exited, code=exited, status=2/INVALIDARGUMENT
Feb 20 13:38:11 alex-arch systemd[995]: Failed to start random wallpaper setter.
Feb 20 13:38:11 alex-arch systemd[995]: Unit feh-wallpaper.service entered failed state.
Feb 20 13:38:11 alex-arch systemd[995]: feh-wallpaper.service failed.
Raynman wrote:

It might be nicer to set something up (with systemctl --user import-environment) to use your actually DISPLAY instead of hardcoding it to :0 and the release notes for systemd 219 mention the inclusion of a scriptlet to do just that.

I looked at the notes, looked good, then found I have systemd 218, so I guess that's not an option yet, but something I'll definitely look into to make things cleaner once it lands.

Last edited by AlexTes (2015-02-20 12:50:15)

Offline

#6 2015-02-20 12:53:36

AlexTes
Member
Registered: 2013-11-16
Posts: 10

Re: feh failes to set a background from systemd unit

To make things easier, unit is down to:

[Unit]
Description=random wallpaper setter

[Service]
Type=oneshot
Environment=DISPLAY=:0
ExecStart=/bin/bash -c '/usr/bin/feh --bg-fill /home/alexander/Pictures/wallpapers/wallwalls/1385132452041.jpg'

[Install]
WantedBy=default.target

Status is down to:

● feh-wallpaper.service - random wallpaper setter
   Loaded: loaded (/home/alexander/.config/systemd/user/feh-wallpaper.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Fri 2015-02-20 13:52:08 CET; 1s ago
  Process: 22390 ExecStart=/bin/bash -c /usr/bin/feh --bg-fill /home/alexander/Pictures/wallpapers/wallwalls/1385132452041.jpg (code=exited, status=2)
 Main PID: 22390 (code=exited, status=2)

Feb 20 13:52:08 alex-arch bash[22390]: feh ERROR: Can't open X display. It *is* running, yeah?
Feb 20 13:52:08 alex-arch systemd[995]: feh-wallpaper.service: main process exited, code=exited, status=2/INVALIDARGUMENT
Feb 20 13:52:08 alex-arch systemd[995]: Failed to start random wallpaper setter.
Feb 20 13:52:08 alex-arch systemd[995]: Unit feh-wallpaper.service entered failed state.
Feb 20 13:52:08 alex-arch systemd[995]: feh-wallpaper.service failed.

Offline

#7 2015-02-20 16:28:03

Knute
Member
From: Minot, ND
Registered: 2009-03-17
Posts: 604

Re: feh failes to set a background from systemd unit

Sounds to me like you need to put an After= line into your unit, so that you can ensure that X is actually started before feh is called.  Perhaps something to the effect of

After=default.target

I haven't tested it but it should work.  Either an after line or a Requires line. I suggested after because the default target, from what I understand anyway, makes sure that X is started.


Knute

Offline

#8 2015-02-21 14:13:17

AlexTes
Member
Registered: 2013-11-16
Posts: 10

Re: feh failes to set a background from systemd unit

Knute wrote:

Sounds to me like you need to put an After= line into your unit, so that you can ensure that X is actually started before feh is called.  Perhaps something to the effect of

After=default.target

Added 'After=default.target' to the unit section. Still fails. I also don't understand how that could fix things because as I mentioned the unit is restarted from a second timer unit. For testing I restart it by hand. Unless I'm really missing something about how systemd functions, default.target has long finished loading when I restart the service unit from shell.

Fails with:

● feh-wallpaper.service - random wallpaper setter
   Loaded: loaded (/home/alexander/.config/systemd/user/feh-wallpaper.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Sat 2015-02-21 15:07:52 CET; 4s ago
  Process: 11052 ExecStart=/bin/bash -c /usr/bin/feh --bg-fill /home/alexander/Pictures/wallpapers/wallwalls/1385132452041.jpg (code=exited, status=2)
 Main PID: 11052 (code=exited, status=2)

Feb 21 15:07:52 alex-arch systemd[2695]: Starting random wallpaper setter...
Feb 21 15:07:52 alex-arch bash[11052]: No protocol specified
Feb 21 15:07:52 alex-arch bash[11052]: feh ERROR: Can't open X display. It *is* running, yeah?
Feb 21 15:07:52 alex-arch systemd[2695]: feh-wallpaper.service: main process exited, code=exited, status=2/IN...UMENT
Feb 21 15:07:52 alex-arch systemd[2695]: Failed to start random wallpaper setter.
Feb 21 15:07:52 alex-arch systemd[2695]: Unit feh-wallpaper.service entered failed state.
Feb 21 15:07:52 alex-arch systemd[2695]: feh-wallpaper.service failed.
Hint: Some lines were ellipsized, use -l to show in full.

It's weird how the logs sometimes differ a little. But that's just systemd it seems.

Anyway, looks like a badly messed something arbitrary up. Maybe its a problem from the permission hiatus I caused a while back messing with my 'group' file. I was going to reinstall anyway. I'll edit this if the problem persists.

Last edited by AlexTes (2015-02-21 14:14:11)

Offline

#9 2015-02-21 14:26:02

Knute
Member
From: Minot, ND
Registered: 2009-03-17
Posts: 604

Re: feh failes to set a background from systemd unit

I was just wondering if the Display variable might be causing problems.  Perhaps removing the Environment line setting DISPLAY may help.  It just doesn't look right.


Knute

Offline

Board footer

Powered by FluxBB