feat(restic): migrate to systemd template units
This commit is contained in:
3
roles/restic/templates/restic.conf.j2
Normal file
3
roles/restic/templates/restic.conf.j2
Normal file
@ -0,0 +1,3 @@
|
||||
{% for kv in restic_complete_environment | dict2items %}
|
||||
{{ kv.key }}={{ kv.value }}
|
||||
{% endfor %}
|
@ -1,51 +0,0 @@
|
||||
[Unit]
|
||||
Description={{ restic_job_description }}
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User={{ restic_user }}
|
||||
WorkingDirectory={{ restic_systemd_working_directory }}
|
||||
SyslogIdentifier={{ restic_systemd_syslog_identifier }}
|
||||
|
||||
Environment=RESTIC_REPOSITORY={{ restic_repo_url }}
|
||||
Environment=RESTIC_PASSWORD={{ restic_repo_password }}
|
||||
{% for kv in restic_complete_environment | dict2items %}
|
||||
Environment={{ kv.key }}={{ kv.value }}
|
||||
{% endfor %}
|
||||
|
||||
{% if restic_init | default(true) %}
|
||||
ExecStartPre=-/bin/sh -c '/usr/bin/restic snapshots || /usr/bin/restic init'
|
||||
{% endif %}
|
||||
{% if restic_unlock_before_backup | default(false) %}
|
||||
ExecStartPre=-/bin/sh -c 'sleep 3 && /usr/bin/restic unlock'
|
||||
{% endif %}
|
||||
{% if restic_backup_pre_hook | default(false) %}
|
||||
ExecStartPre=-{{ restic_backup_pre_hook }}
|
||||
{% endif %}
|
||||
{% if restic_backup_stdin_command %}
|
||||
ExecStart=/bin/sh -c '{{ restic_backup_stdin_command }} | /usr/bin/restic backup \
|
||||
--retry-lock {{ restic_retry_lock | default('5m') }} \
|
||||
--verbose --stdin \
|
||||
--stdin-filename {{ restic_backup_stdin_command_filename }}'
|
||||
{% else %}
|
||||
ExecStart=/opt/restic-backup-directories.sh {{ restic_backup_paths | join(' ') }}
|
||||
{% endif %}
|
||||
{% if restic_forget_prune | default(true) %}
|
||||
ExecStartPost=/usr/bin/restic forget --prune \
|
||||
--retry-lock {{ restic_retry_lock | default('5m') }} \
|
||||
--keep-within={{ restic_policy.keep_within }} \
|
||||
--keep-hourly={{ restic_policy.hourly }} \
|
||||
--keep-daily={{ restic_policy.daily }} \
|
||||
--keep-weekly={{ restic_policy.weekly }} \
|
||||
--keep-monthly={{ restic_policy.monthly }} \
|
||||
--keep-yearly={{ restic_policy.yearly }}
|
||||
{% endif %}
|
||||
{% if restic_list_snapshots | default(true) %}
|
||||
ExecStartPost=-/usr/bin/restic snapshots --retry-lock {{ restic_retry_lock | default('5m') }}
|
||||
{% endif %}
|
||||
{% if restic_backup_post_hook | default(false) %}
|
||||
ExecStartPost=-{{ restic_backup_post_hook }}
|
||||
{% endif %}
|
||||
{% if restic_check | default(true) %}
|
||||
ExecStartPost=/usr/bin/restic check --retry-lock {{ restic_retry_lock | default('5m') }}
|
||||
{% endif %}
|
15
roles/restic/templates/restic@.service.j2
Normal file
15
roles/restic/templates/restic@.service.j2
Normal file
@ -0,0 +1,15 @@
|
||||
[Unit]
|
||||
Description={{ restic_systemd_job_description }}
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
EnvironmentFile={{ restic_job_directory }}/%i.conf
|
||||
User={{ restic_user }}
|
||||
WorkingDirectory={{ restic_systemd_working_directory }}
|
||||
SyslogIdentifier={{ restic_systemd_syslog_identifier }}
|
||||
|
||||
ExecStart={{ restic_systemd_service_exec_start }}
|
||||
|
||||
[Install]
|
||||
WantedBy={{ restic_systemd_install_wanted_by }}
|
||||
DefaultInstance={{ restic_systemd_install_default_instance }}
|
Reference in New Issue
Block a user