0

I currently have this timer:

[Unit]
Description=Schedule wallpaper rotation

[Timer]
OnCalendar=*-*-* *:00:00
Persistent=true

[Install]
WantedBy=graphical-session.target

Which runs this service:

[Unit]
Description=Rotate wallpapers

[Service]
Type=oneshot
ExecStart=%h/bin/wpman %h/docs/media/wallpaper/arkady

Which runs this script:

#!/bin/bash

TARGET="${1}"
CURRENT=
NEXT=
REST=
LISTFILE="${HOME}/.wallpaper-list"
TARGFILE="${HOME}/.wallpaper-target"
WALLFILE="${HOME}/.wallpaper"

if [[ ! -d "${TARGET}" ]]; then
  echo "Invalid target: '${TARGET}'"
  exit 1
fi
TARGET="$(realpath "${TARGET}")"
[[ -f "${TARGFILE}" ]] && CURRENT="$(cat "${TARGFILE}")"
if [[ -f "${LISTFILE}" ]]; then
  NEXT="$(head -n 1 "${LISTFILE}")"
  REST="$(tail -n +2 "${LISTFILE}")"
fi

mklist() {
  find "${TARGET}" -mindepth 1 -maxdepth 1 -type f | sort -R > "${LISTFILE}"
  echo "${TARGET}" > "${TARGFILE}"
  NEXT="$(head -n 1 "${LISTFILE}")"
  REST="$(tail -n +2 "${LISTFILE}")"
}

set-wallpaper() {
  feh --bg-fill "${NEXT}"
  echo "${REST}" > "${LISTFILE}"
  cp "${NEXT}" "${WALLFILE}"
}

if [[ -z "${CURRENT}" ]] || ([[ -n "${CURRENT}" ]] && [[ "${CURRENT}" != "${TARGET}" ]]) || [[ ! -f "${LISTFILE}" ]] || [[ -z "${NEXT}" ]]; then
  mklist
fi

set-wallpaper

But it doesn't start. I thought about just starting it from timers.target and checking in my script if $DISPLAY is empty and exiting if so, but I'm not sure if $DISPLAY will be available to the script if started this way. FWIW, I'm not running any desktop environment, just X and a window manager. I'm not sure if that effects how graphical-session.target is triggered.

Is there a way to get this to work how I want? Maybe a systemd timer wasn't the best approach.

Abacus Lever
  • 103
  • 4
  • What will your **unit timer** do? Will it run some GUI app when the graphical session is ready? – Edgar Magallon Nov 29 '22 at 04:20
  • It runs a bash script which changes my wallpaper once per hour, with some bells and whistles, using `feh`. – Abacus Lever Nov 29 '22 at 06:13
  • Can you add to your question the content of your bash script? Also, you have the systemd timer, it's ok, but do you have the systemd service too? *(systemd timers must trigger a systemd service)*. If you do, then please provide what you have in the systemd service. – Edgar Magallon Nov 29 '22 at 06:29
  • There is a service. It all works fine if I start the timer manually (I probably should have mentioned that), the problem is just that it won't start on its own. I don't see how the content of the service or the script would effect that but I'll add them to my question in a second. – Abacus Lever Nov 29 '22 at 06:44
  • Oh! I think your main problem is that you have not enabled your systemd timer. Try this: `sudo systemctl enable your_timer.timer`. When you restart your machine the timer should be active (and maybe ready and waiting for triggering your systemd service) – Edgar Magallon Nov 29 '22 at 06:54
  • Afraid not, it's already enabled. To be clear, this is a user service/timer. I thought that seemed more sensible for something like this but maybe not? – Abacus Lever Nov 29 '22 at 06:58
  • Well, given that is not working on its own, then the systemd timer should produce some logs about the errors, (I assume). And as you said is a user service/timer then try this to see their logs: `journalctl --user -eu your_timer.timer` and `journalctl --user -eu your_service.service`. Hopefully you find what is going on (maybe the issue is related to `$DISPLAY` as you indicated in your question, or another issue could be related to `$XAUTHORITY`). If you get useful information then add it to your question. – Edgar Magallon Nov 29 '22 at 07:11
  • Btw, not sure if this is so useful but try adding in your systemd timer (at **[Unit]** section,after Description) this: `After=graphical-session.target` – Edgar Magallon Nov 29 '22 at 07:14

1 Answers1

1

FWIW, I'm not running any desktop environment, just X and a window manager. I'm not sure if that effects how graphical-session.target is triggered.

It does – the .target needs to be explicitly started by your ~/.xinitrc (or by your WM's "autostart").

graphical-session.target is not started automatically by Xorg for every GUI session, only pulled in as a dependency in specific situations (such as by gnome-session.target, as GNOME primarily uses systemd for session management).

u1686_grawity
  • 4,580
  • 20
  • 27
  • That did it, thanks. From here I essentially followed what's shown in this answer: https://superuser.com/a/1128905/636739 – Abacus Lever Nov 29 '22 at 17:46