systemd - Timers
Updated at 2018-02-06 17:52
Debug commands for timers.
systemctl --all # list all systemd "units"
systemctl list-timers # list all systemd timers
systemctl start cleanup.timer # start a specific timer
/files/cleanup.service
[Unit] # section defines service metadata
Description=Cleanup # human-readable name
After=network.target # when will the service be started
[Service] # defines configuration for services
Type=oneshot # one-off task, manager will wait for this to finish
ExecStart=/bin/echo hello # what to run
[Install] # section defines behavior when enabled
WantedBy=multi-user.target # start when the target (multi-user runlevel) starts
files/cleanup.timer
[Unit] # section defines service metadata
Description=Cleanup Timer # human-readable name
[Timer] # defines configuration for timers
OnCalendar=*:0/15 # ran every 15 minutes
Persistent=true # ran immediately if should've ran when timer was inactive
[Install] # section defines behavior when enabled
WantedBy=timers.target # start when the target (timer manager) starts
tasks/install-server.yml
, example Ansible setup.
# ...
- name: copy cleanup job file
become: true
copy:
src: ../files/cleanup.service
dest: /etc/systemd/system/cleanup.service
- name: copy cleanup timer file
become: true
copy:
src: ../files/cleanup.timer
dest: /etc/systemd/system/cleanup.timer
- name: enable cleaning service
become: true
systemd:
name: cleanup.timer
state: started
enabled: true