Skip to content

Commit bdee511

Browse files
m3nuclaude
andcommitted
fix: correct systemd timer reference and enable timer by default
Fixes #143 and #164. - Fix incorrect timer reference in borgmatic.service.j2 (backup_normal_repo.timer -> borgmatic.timer) - Add borgmatic_timer_enabled variable (default: true) to control whether the systemd timer is enabled after installation - Simplify timer management logic in noauto_create_timer_systemd.yml Previously, the timer was always created but never enabled, causing users to think backups were running when they weren't. Now the timer is enabled by default. Users who need manual control can set borgmatic_timer_enabled: false. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 91e7939 commit bdee511

4 files changed

Lines changed: 24 additions & 27 deletions

File tree

defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ borgmatic_timer: cron
2323
borgmatic_timer_hour: "{{ range(0, 5) | random(seed=inventory_hostname) }}"
2424
borgmatic_timer_minute: "{{ range(0, 59) | random(seed=inventory_hostname) }}"
2525
borgmatic_timer_flags: ""
26+
borgmatic_timer_enabled: true
2627
borgmatic_systemd_nonewprivileges: "yes"
2728
borg_install_method: "pip"
2829
borg_require_epel: "{{ ansible_os_family == 'RedHat' and ansible_distribution != 'Fedora' }}"

meta/argument_specs.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ argument_specs:
203203
type: str
204204
required: false
205205
description: Flags to pass to borgmatic cron/systemd-timer job, like "--log-file /path/to/file.log --log-file-verbosity 2"
206+
borgmatic_timer_enabled:
207+
type: bool
208+
required: false
209+
default: true
210+
description: Whether to enable and start the systemd timer after installation. Set to false to start the timer manually.
206211
borgmatic_systemd_nonewprivileges:
207212
type: str
208213
required: false

tasks/noauto_create_timer_systemd.yml

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,39 +29,30 @@
2929
- { src: "borgmatic.timer.j2", dest: "/usr/lib/systemd/system/borgmatic.timer", mode: "0644" }
3030
- { src: "borgmatic.service.j2", dest: "/usr/lib/systemd/system/borgmatic.service", mode: "0644" }
3131

32-
- name: Populate service facts
33-
ansible.builtin.service_facts:
32+
- name: Reload systemd daemon
33+
ansible.builtin.systemd:
34+
daemon_reload: true
3435

35-
# If the role is running and the repo is not yet initialized, an error will occur.
36-
# Therefore the service is stopped by default and must be started manually.
37-
- name: Stop fresh installed borgmatic.timer and borgmatic.service
38-
when: "'borgmatic.service' not in ansible_facts.services"
39-
block:
40-
- name: Set borgmatic services to stopped - newly installed
41-
ansible.builtin.systemd:
42-
name: "{{ item }}"
43-
state: stopped
44-
enabled: false
45-
masked: false
46-
daemon_reload: true
47-
when: item in ansible_facts.services
48-
with_items:
49-
- borgmatic.service
36+
- name: Enable and start borgmatic timer
37+
when: borgmatic_timer_enabled | default(true) | bool
38+
ansible.builtin.systemd:
39+
name: borgmatic.timer
40+
state: started
41+
enabled: true
5042

51-
# bug: Need own section without masked else the timer are skipped
52-
- name: Set borgmatic timers to stopped - newly installed
43+
- name: Disable borgmatic timer
44+
when: not (borgmatic_timer_enabled | default(true) | bool)
45+
block:
46+
- name: Stop and disable borgmatic.timer
5347
ansible.builtin.systemd:
54-
name: "{{ item }}"
48+
name: borgmatic.timer
5549
state: stopped
5650
enabled: false
57-
daemon_reload: true
58-
with_items:
59-
- "borgmatic.timer"
6051

6152
- name: Show hints
62-
when: "'backup_init_repo' not in ansible_run_tags"
6353
ansible.builtin.debug:
6454
msg: >-
65-
Attention: Since the repo was not initialized automatically,
66-
the systemd service (borgmatic.service) and the timer (borgmatic.timer) are not activated.
55+
Attention: borgmatic_timer_enabled is set to false.
56+
The systemd timer (borgmatic.timer) is not activated.
57+
Enable it manually with: systemctl enable --now borgmatic.timer
6758
...

templates/borgmatic.service.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[Unit]
44
Description=borgmatic backup
5-
Wants=backup_normal_repo.timer
5+
Wants=borgmatic.timer
66
Wants=network-online.target
77
After=network-online.target
88
# Prevent borgmatic from running unless the machine is plugged into power. Remove this line if you

0 commit comments

Comments
 (0)