炸蝦碎碎念。

[Notes, GNU/Linux, Open Source, Ruby on Rails, Computer Science, Archlinux]

[Archlinux] Writing Timer Units to Do Daily System Upgrade in Systemd

In Archlinux, crontab is not installed by default because of systemd. Doing system upgrade every day can be achieved by writing timer unit and oneshot service of systemd.

By default, user-defined systemd unit files (.service, .target, .timer…etc) is located in /etc/systemd/system

  1. service file

    see man systemd.service for more info.

         # /etc/systemd/system/system-upgrade.service
         [Unit]
         Description=Full System Upgrade
    
         [Service]
         Type=oneshot
         ExecStart=/usr/bin/pacman -Syu --noconfirm
    
         [Install]
         WantedBy=multi-user.target
    
  2. timer file

    see man systemd.timer and systemd.time for more info.

         # /etc/systemd/system/system-upgrade.service
         [Timer]
         OnCalendar=daily
         Unit=/etc/systemd/system/system-upgrade.service
         [Install]
         WantedBy=multi-user.target
    
  3. enable the timer

    sudo systemctl start system-upgrade.timer & sudo systemctl enable system-upgrade.timer.

  4. reference systemd/Timers - Archwiki

Comments