I have a directory that a git repo is checked out to /tftpboot
If I am in that directory and use git pull
, all is as I want it. Great.
Now I want to schedule git pull
to run every hour.
I could use cron
easily enough, but I want to get more current and use systemd
as it is the current control mechanism.
Reading these results:
https://wiki.archlinux.org/index.php/Systemd/Timers
https://www.certdepot.net/rhel7-use-systemd-timers/
I learn i need to use a service file and a timer file. Easy enough. Here is what you do.
First create the .service file in /etc/systemd/system
# I like nano, use vi if you want
nano /etc/systemd/system/gitpull.service
In that file, you need this
[Unit]
Description=update /tftpboot with git pull
[Service]
Type=simple
ExecStart=/bin/git --git-dir=/tftpboot/.git --work-tree=/tftpboot/ pull
[Install]
WantedBy=multi-user.target
That git
command is extra annoying because CentOS 7 is still on git version 1.8.3.x and the cleaner -C switch doesn't arrive until git 1.8.5.
Anyway, next create a .timer
file also in /etc/systemd/system
nano /etc/systemd/system/gitpull.timer
Put this information in it.
[Unit]
Description=Execute git pull every hour on the hour
[Timer]
OnCalendar=*-*-* *:00:00
Unit=gitpull.service
[Install]
WantedBy=multi-user.target
The ArchLinux wiki link above explains the syntax for OnCalendar
Once you have these two files, you simply enable and start it with systemctl
just like anything else.
systemctl enable gitpull.timer
systemctl start gitpull.timer
Special thanks to @stacksofplates for his advice via Telegram