home
clear breadcrumbs
search
login
 
systemd
https://opensource.com/article/20/7/systemd-timers Service unit: For each .timer file, a matching .service file exists (e.g. foo.timer and foo.service). The .timer file activates and controls the .service file. The .service does not require an [Install] section as it is the timer units that are enabled. If necessary, it is possible to control a differently-named unit using the Unit= option in the timer's [Timer] section. # pound for comments create service unit file: /etc/systemd/system/rsync_run.service [Unit] Description=Run rsync to update backups Wants=rsync_run.timer [Service] Type=oneshot ExecStart=/home/pete/bin/rsync_run [Install] WantedBy=multi-user.target view the staus of the service: sudo systemctl status rsync_run.service journalctl -f option: sudo journalctl -S today -f -u rsync_run.service (tail) start / run the service: sudo systemctl start rsync_run.service view the logs of the service: sudo journalctl -S today -u rsync_run.service create timer: /etc/systemd/system/rsync_run.timer [Unit] Description=Run rsync_run.service to update backups Requires=rsync_run.service [Timer] Unit=rsync_run.service OnCalendar=*-*-* *:*:00 [Install] WantedBy=timers.target start but don't enable the service: systemctl start rsync_run.service (in the case of a script, it will only run once) *:0/1 Every minute *-*-* 00:15:30 Every day of every month of every year at 15 minutes and 30 seconds after midnight Weekly Every Monday at 00:00:00 systemctl daemon-reload systemctl list-units systemctl status *timer systemctl daemon-reload *** has to be run after any changes systemctl enable --now rsync_run.timer systemd-analyze calendar 'Fri *-*-* 00:00:00' systemctl edit file --full *** no need to reload file, only works on existing files **** systemctl list-units --type=service systemctl disable [service_name] systemctl enable [service_name] systemctl start [service_name] systemctl stop [service_name]