Systemd/timers: Difference between revisions

added alternative example of the call for the binary and command, the quotes confused me when replicating this for rclone (maybe more me but didn't seem like it hurt to add)
H7x4 (talk | contribs)
Add section about systemd.services.<name>.startAt
Line 45: Line 45:
foo command-options
foo command-options
</syntaxhighlight>
</syntaxhighlight>
in your terminal.  
in your terminal.
 
====Using the <code>systemd.services.&lt;name&gt;.startAt</code> shorthand====
 
If you only want a service to execute at an interval and don't plan to configure the timer much more, you can use the <code>systemd.services.&lt;name&gt;.startAt</code> option. This will have the underlying systemd module in nixpkgs create the timer for you, and set its <code>OnCalendar</code> field. Note that the semantics for <code>OnCalendar</code> are different to <code>OnUnitActiveSec</code>.
 
This example shows the previous <code>hello-world</code> service configured with <code>startAt</code>, running every 5 minutes.
 
<syntaxHighlight lang="nix">
systemd.services."hello-world" = {
  script = ''
    set -eu
    ${pkgs.coreutils}/bin/echo "Hello World"
  '';
  serviceConfig = {
    Type = "oneshot";
    User = "root";
  };
  startAt = "*:0/5";
};
</syntaxHighlight>


====Running timer on a schedule====
====Running timer on a schedule====