Skip to content

Instantly share code, notes, and snippets.

@soyfrien
Created November 9, 2021 06:57
Show Gist options
  • Save soyfrien/c06cf37da272ffd182c575cf99a208a7 to your computer and use it in GitHub Desktop.
Save soyfrien/c06cf37da272ffd182c575cf99a208a7 to your computer and use it in GitHub Desktop.
How Azure Implements systemd timers to trim SSDs and Kind of Scared to Make Azure Services Now
[Unit]
Description=Discard unused blocks on filesystems from /etc/fstab
Documentation=man:fstrim(8)
ConditionVirtualization=!container
[Service]
Type=oneshot
ExecStart=/sbin/fstrim --fstab --verbose --quiet
ProtectSystem=strict
ProtectHome=yes
PrivateDevices=no
PrivateNetwork=yes
PrivateUsers=no
ProtectKernelTunables=yes
ProtectKernelModules=yes
ProtectControlGroups=yes
MemoryDenyWriteExecute=yes
SystemCallFilter=@default @file-system @basic-io @system-service
@soyfrien
Copy link
Author

soyfrien commented Nov 9, 2021

Context:

$ ls -lha timers.target.wants/fstrim.timer 
lrwxrwxrwx 1 root root 32 Jun 23 00:11 timers.target.wants/fstrim.timer -> /lib/systemd/system/fstrim.timer

louis@:/etc/systemd/system$ cat /lib/systemd/system/fstrim.timer
[Unit]
Description=Discard unused blocks once a week
Documentation=man:fstrim
ConditionVirtualization=!container

[Timer]
OnCalendar=weekly
AccuracySec=1h
Persistent=true

[Install]
WantedBy=timers.target

louis@node:/etc/systemd/system$ sudo systemctl list-timers
NEXT                        LEFT          LAST                        PASSED       UNIT                         ACTIVATES       >
Mon 2021-11-15 00:00:00 UTC 5 days left   Mon 2021-11-08 00:00:10 UTC 1 day 6h ago fstrim.timer                 fstrim.service  >

9 timers listed.
Pass --all to see loaded but inactive timers, too.
louis@node:/etc/systemd/system$ systemctl status fstrim.service
● fstrim.service - Discard unused blocks on filesystems from /etc/fstab
     Loaded: loaded (**/lib/systemd/system/fstrim.service**; static; vendor preset: enabled)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment