Systemd service not running regularly

I copied and edited the example from the wiki for to run a shell script every x minutes, but it only runs once on boot for me (and successfully).

  systemd.timers."wallpaper" = {
    wantedBy = [ "timers.target" ];
    timerConfig = {
      OnBootSec = "1s";
      OnUnitActiveSec = "1m";
      Unit = "wallpaper.service";
    };
  };
  systemd.user.services."wallpaper" = {
    script = ''
      			set -eu
            /run/current-system/sw/bin/fish /pathto/fishscript.fish
    '';
    serviceConfig = {
      Type = "oneshot";
      User = "myusername";
      RemainAfterExit = true;
      PrivateTmp = true;
    };
  };

They need to both be user or both not. having the timer be a system unit and the service be a user unit isn’t going to work.

Also, RemainAfterExit = true; may mess with what you want to happen here. You want the service to end so it can be started again the next time.

2 Likes

Yep, I needed to apply both those things, this is my config now:

  systemd.user.timers."wallpaper" = {
    wantedBy = [ "timers.target" ];
    timerConfig = {
      OnBootSec = "1s";
      OnUnitActiveSec = "1m";
      Unit = "wallpaper.service";
    };
  };
  systemd.user.services."wallpaper" = {
    script = ''
      /run/current-system/sw/bin/fish /path/to/script.fish
    '';
    serviceConfig = {
      Type = "oneshot";
      User = "myusername";
      PrivateTmp = true;
    };
  };