Systemd pour ceux qui continuent. Partie 1 - Exécution des unités sur des événements chronométrés

! systemd , ( , . ( ) . Manjaro Linux c systemd v247.2. ... . , , « -», , , !





Systemd — Linux, . , :





pacman -Ql $(pacman -Qsq systemd|xargs)|egrep '^systemd\s|^systemd-sysvcompat\s'|egrep "man/man[1|5|8]/[[:print:]]*\.gz"|wc -l
278
      
      



, systemd. , «»:





pacman -Ql $(pacman -Qsq systemd|xargs)|egrep '^systemd\s|^systemd-sysvcompat\s'|wc -l
1852
      
      



, . -, , !





Disclamer: ( «triggered by»), , , . - , , , , .





, . .

, cron



, . 80-, , , . - . / , , . - , systemd ( *.timer



) (*.target



) ; - ; ; ( Unix , at



), - , , , .






 . , , man-db.timer :





$ cat /usr/lib/systemd/system/man-db.timer
[Unit]
Description=Daily man-db regeneration
Documentation=man:mandb(8)

[Timer]
OnCalendar=daily
AccuracySec=12h
Persistent=true

[Install]
WantedBy=timers.target
      
      



, . - , ? ! , [Timer]



Unit=



, , systemd *.service



. !





$ cat /usr/lib/systemd/system/man-db.service
[Unit]
Description=Daily man-db regeneration
Documentation=man:mandb(8)
ConditionACPower=true

[Service]
Type=oneshot
# Recover from deletion, per FHS.
ExecStart=+/usr/bin/install -d -o root -g root -m 0755 /var/cache/man
# Expunge old catman pages which have not been read in a week.
ExecStart=/usr/bin/find /var/cache/man -type f -name *.gz -atime +6 -delete
# Regenerate man database.
ExecStart=/usr/bin/mandb --quiet
User=root
Nice=19
IOSchedulingClass=idle
IOSchedulingPriority=7
      
      



, . 00:00 (OnCalendar=daily



) , 12 (AccuracySec=12h



), - , :





$ systemctl status man-db.timer 
● man-db.timer - Daily man-db regeneration
     Loaded: loaded (/usr/lib/systemd/system/man-db.timer; disabled; vendor preset: disabled)
     Active: active (waiting) since Thu 2020-12-31 23:18:59 MSK; 1 day 19h ago
    Trigger: Sun 2021-01-03 00:00:00 MSK; 5h 30min left
   Triggers: ● man-db.service
       Docs: man:mandb(8)

 31 23:18:59 dell-lnx systemd[1]: Started Daily man-db regeneration.
      
      



AccuracySec=



— 1us! , . , ( /etc/systemd/system.conf



: DefaultTimerAccuracySec=



) . , , [Timer]



, OnCalendar=



«» .





,

  • OnBootSec=



    .





  • OnStartupSec=



    , , .





  • OnActiveSec=



    . , , .





  • OnUnitActiveSec=



    .





  • OnUnitInactiveSec=



    . . . OnCalendar=



    .





  • RandomizedDelaySec=



    . , . -- .





  • OnClockChange=, OnTimezoneChange=



    , - . , , false



    .





  • Persistent=



    - . OnCalendar=



    . — false



    .





  • WakeSystem=



    . . . . , . , « ». - true



    , ( ) .





  • RemainAfterElapse=



    , true



    , , false



    , . (Transient Units) . , , at



    .





, , ,

. , , cron , , . :





[Unit]
Description=Test timer

[Timer]
OnCalendar=01:00
OnActiveSec=1.5h
      
      



. - 13-
 OnCalendar=Fri *-*-13 12:00:00



: Mon 2025-12-01 00:00:00.000000 Europe/Moscow



( ) - , : OnCalendar=yearly Asia/Kamchatka



( - ):

OnCalendar=*-01-01 00:00:00 Asia/Kamchatka



( ) :





                       minutely → *-*-* *:*:00
                         hourly → *-*-* *:00:00
                          daily → *-*-* 00:00:00
                        monthly → *-*-01 00:00:00
                         weekly → Mon *-*-* 00:00:00
                         yearly → *-01-01 00:00:00
                      quarterly → *-01,04,07,10-01 00:00:00                                                      
                   semiannually → *-01,07-01 00:00:00
      
      



:





@ — epoch time
        Fri 2012-11-23 11:12:13 → Fri 2012-11-23 11:12:13
            2012-11-23 11:12:13 → Fri 2012-11-23 11:12:13
        2012-11-23 11:12:13 UTC → Fri 2012-11-23 19:12:13
                     2012-11-23 → Fri 2012-11-23 00:00:00
                       12-11-23 → Fri 2012-11-23 00:00:00
                       11:12:13 → Fri 2012-11-23 11:12:13
                          11:12 → Fri 2012-11-23 11:12:00
                            now → Fri 2012-11-23 18:15:22
                          today → Fri 2012-11-23 00:00:00
                      today UTC → Fri 2012-11-23 16:00:00
                      yesterday → Fri 2012-11-22 00:00:00
                       tomorrow → Fri 2012-11-24 00:00:00
      tomorrow Pacific/Auckland → Thu 2012-11-23 19:00:00
                       +3h30min → Fri 2012-11-23 21:45:22
                            -5s → Fri 2012-11-23 18:15:17
                      11min ago → Fri 2012-11-23 18:04:22
                    @1395716396 → Tue 2014-03-25 03:59:56
      
      



OnCalendar=



, .





:





      Sat,Thu,Mon..Wed,Sat..Sun → Mon..Thu,Sat,Sun *-*-* 00:00:00
          Mon,Sun 12-*-* 2,1:23 → Mon,Sun 2012-*-* 01,02:23:00
                        Wed *-1 → Wed *-*-01 00:00:00
               Wed..Wed,Wed *-1 → Wed *-*-01 00:00:00
                     Wed, 17:48 → Wed *-*-* 17:48:00
    Wed..Sat,Tue 12-10-15 1:2:3 → Tue..Sat 2012-10-15 01:02:03
                    *-*-7 0:0:0 → *-*-07 00:00:00
                          10-15 → *-10-15 00:00:00
            monday *-12-* 17:00 → Mon *-12-* 17:00:00
      Mon,Fri *-*-3,1,2 *:30:45 → Mon,Fri *-*-01,02,03 *:30:45
           12,14,13,12:20,10,30 → *-*-* 12,13,14:10,20,30:00
                12..14:10,20,30 → *-*-* 12..14:10,20,30:00
      mon,fri *-1/2-1,3 *:30:45 → Mon,Fri *-01/2-01,03 *:30:45
                 03-05 08:05:40 → *-03-05 08:05:40
                       08:05:40 → *-*-* 08:05:40
                          05:40 → *-*-* 05:40:00
         Sat,Sun 12-05 08:05:40 → Sat,Sun *-12-05 08:05:40
               Sat,Sun 08:05:40 → Sat,Sun *-*-* 08:05:40
               2003-03-05 05:40 → 2003-03-05 05:40:00
     05:40:23.4200004/3.1700005 → *-*-* 05:40:23.420000/3.170001
                 2003-02..04-05 → 2003-02..04-05 00:00:00
           2003-03-05 05:40 UTC → 2003-03-05 05:40:00 UTC
                     2003-03-05 → 2003-03-05 00:00:00
                          03-05 → *-03-05 00:00:00
                         hourly → *-*-* *:00:00
                          daily → *-*-* 00:00:00
                      daily UTC → *-*-* 00:00:00 UTC
                        monthly → *-*-01 00:00:00
                         weekly → Mon *-*-* 00:00:00
        weekly Pacific/Auckland → Mon *-*-* 00:00:00 Pacific/Auckland
                         yearly → *-01-01 00:00:00
                       annually → *-01-01 00:00:00
                          *:2/3 → *-*-* *:02/3:00
      
      







. , :





  • *-*~01



    - Le premier jour de la fin de chaque mois (c'est le dernier jour du mois).





  • *-05~05



    - 27 mai de chaque année (31-5).





  • Mon *-12~07/1



    - Lundi dernier de décembre.





  • Mon *-12-01/3



    - TroisiÚme lundi de décembre.





Vous pouvez vérifier la validité des horodatages à l'aide de l'utilitaire systemd-analyze



:





$ systemd-analyze calendar 'Mon *-12-01/1'
  Original form: Mon *-12-01/1              
Normalized form: Mon *-12-01/1 00:00:00     
    Next elapse: Mon 2021-12-06 00:00:00 MSK
       (in UTC): Sun 2021-12-05 21:00:00 UTC
       From now: 11 months 2 days left

$ systemd-analyze timespan 1.5h
Original: 1.5h      
      ÎŒs: 5400000000
   Human: 1h 30min

$ systemd-analyze timestamp 01:00:30.9999
  Original form: 01:00:30.9999              
Normalized form: Sat 2021-01-02 01:00:30 MSK
       (in UTC): Fri 2021-01-01 22:00:30 UTC
   UNIX seconds: @1609538430.999900         
       From now: 18h ago 
      
      



Donc, en principe, tout est simple, logique et beau. Et bien sûr, lisez:





man systemd.timer
man systemd.time
man systemd-system.conf
man systemd-analyze
man tzselect
      
      



Liste des articles de la série

  1. Pourquoi les propriétaires d'entreprise préfÚrent-ils les vélos aux solutions toutes faites? Ou à propos de systemd, partie 0





  2. Systemd pour ceux qui continuent. Partie 1 - Exécution des unités sur des événements chronométrés












All Articles