Systemd/timers/ru: Difference between revisions

FuzzyBot (talk | contribs)
Updating to match new version of source page
Tags: Mobile edit Mobile web edit
FuzzyBot (talk | contribs)
Updating to match new version of source page
 
Line 6: Line 6:
== Настройка ==
== Настройка ==
Следующий пример таймера запускает каждые 5 минут юнит systemd, который вызывает сценарий bash.
Следующий пример таймера запускает каждые 5 минут юнит systemd, который вызывает сценарий bash.
<syntaxHighlight lang="nix">
<syntaxhighlight lang="nix">
systemd.timers."hello-world" = {
systemd.timers."hello-world" = {
   wantedBy = [ "timers.target" ];
   wantedBy = [ "timers.target" ];
Line 12: Line 12:
       OnBootSec = "5m";
       OnBootSec = "5m";
       OnUnitActiveSec = "5m";
       OnUnitActiveSec = "5m";
      # Alternatively, if you prefer to specify an exact timestamp
      # like one does in cron, you can use the `OnCalendar` option
      # to specify a calendar event expression.
      # Run every Monday at 10:00 AM in the Asia/Kolkata timezone.
      #OnCalendar = "Mon *-*-* 10:00:00 Asia/Kolkata";
       Unit = "hello-world.service";
       Unit = "hello-world.service";
     };
     };
Line 24: Line 29:
     Type = "oneshot";
     Type = "oneshot";
     User = "root";
     User = "root";
    RemainAfterExit = true; # Prevents the service from automatically starting on rebuild. See https://discourse.nixos.org/t/how-to-prevent-custom-systemd-service-from-restarting-on-nixos-rebuild-switch/43431
   };
   };
};
};
</syntaxHighlight>
</syntaxhighlight>




Line 40: Line 46:
</syntaxhighlight>
</syntaxhighlight>
in your terminal.
in your terminal.
==== Verifying your timestamp for systemd.time ====
If you do not understand the format that [https://www.freedesktop.org/software/systemd/man/latest/systemd.time.html systemd.time] expects, you can use the <code>systemd-analyze</code>'s <code>calendar</code> sub-command to understand the next ''N'' times when the timer will get triggered. Following is an example:<syntaxhighlight lang="shell-session">
$ systemd-analyze calendar --iterations=5 "10:00:00"
  Original form: 10:00:00
Normalized form: *-*-* 10:00:00
    Next elapse: Sat 2024-12-07 10:00:00 IST
      (in UTC): Sat 2024-12-07 04:30:00 UTC
      From now: 33min left
  Iteration #2: Sun 2024-12-08 10:00:00 IST
      (in UTC): Sun 2024-12-08 04:30:00 UTC
      From now: 24h left
  Iteration #3: Mon 2024-12-09 10:00:00 IST
      (in UTC): Mon 2024-12-09 04:30:00 UTC
      From now: 2 days left
  Iteration #4: Tue 2024-12-10 10:00:00 IST
      (in UTC): Tue 2024-12-10 04:30:00 UTC
      From now: 3 days left
  Iteration #5: Wed 2024-12-11 10:00:00 IST
      (in UTC): Wed 2024-12-11 04:30:00 UTC
      From now: 4 days left
</syntaxhighlight>


====Using the <code>systemd.services.&lt;name&gt;.startAt</code> shorthand====
====Using the <code>systemd.services.&lt;name&gt;.startAt</code> shorthand====