From 1e91b2fac8135a37509d9e8129494a639674e7c6 Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Mon, 22 May 2023 15:45:24 -0400 Subject: poll with timer just to instantiate timers, ugh! This makes everything work through systemd though. The user can simply drop config files into /etc/btrfs-backup/remotes/.json and timers will automatically be created to handle syncing. --- Makefile | 8 +++++++- push-btrfs.path | 6 ++++++ push-btrfs.service | 10 ++++++++++ push-btrfs.timer | 5 +++++ 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 push-btrfs.path create mode 100644 push-btrfs.service create mode 100644 push-btrfs.timer diff --git a/Makefile b/Makefile index ac0ab02..0dd9c7e 100644 --- a/Makefile +++ b/Makefile @@ -5,8 +5,14 @@ ifeq ($(remotes),) $(error You must put at least one *.json configuration file into ). endif +unit_files = push-btrfs.path push-btrfs.service push-btrfs.timer push-btrfs@.service push-btrfs@.timer + +enable_unit = push-btrfs.timer + install: - for remote in $(remotes); do systemctl enable push-btrfs@$$remote.service; systemctl enable --now push-btrfs@$$remote.timer; done + systemctl link $(addprefix ./, $(unit_files)) + systemctl reset-failed $(enable_unit) + systemctl enable --now $(enable_unit) go: for remote in $(remotes); do bash$(if $(verbose), -x) push-btrfs $$remote$(if $(verbose),;, &) done; wait diff --git a/push-btrfs.path b/push-btrfs.path new file mode 100644 index 0000000..1767b1f --- /dev/null +++ b/push-btrfs.path @@ -0,0 +1,6 @@ +[Path] +PathExistsGlob=/etc/btrfs-backup/remotes/*.json +PathChanged=/etc/btrfs-backup/remotes + +[Install] +WantedBy=default.target diff --git a/push-btrfs.service b/push-btrfs.service new file mode 100644 index 0000000..ec9d3cd --- /dev/null +++ b/push-btrfs.service @@ -0,0 +1,10 @@ +[Unit] +Description = Btrfs Backup over SSH +ConditionUser = root + +[Service] +WorkingDirectory = /etc/btrfs-backup/remotes +ExecStart = bash -c 'shopt -s nullglob; for f in *.json; do (set -x; systemctl enable push-btrfs@$$f.timer); done' + +[Install] +WantedBy=default.target diff --git a/push-btrfs.timer b/push-btrfs.timer new file mode 100644 index 0000000..982df5c --- /dev/null +++ b/push-btrfs.timer @@ -0,0 +1,5 @@ +[Timer] +OnUnitInactiveSec=5 + +[Install] +WantedBy=default.target -- cgit v1.2.3