Add user service for syncing voron

This commit is contained in:
Arnie 2025-01-21 09:04:13 +01:00
parent 7c993c502a
commit 7ac33a4974

View File

@ -291,6 +291,45 @@ in
Install.WantedBy = [ "default.target" ];
};
systemd.user.services.voron2-red-sync = {
Unit.Description = "Sync Voron2 red gcodes";
Service = {
Type = "simple";
ExecStart = toString (
pkgs.writeShellScript "voron2-red-sync" ''
echo "Starting sync"
${pkgs.inotify-tools}/bin/inotifywait --monitor --recursive --quiet -e modify -e moved_to -e moved_from -e create -e delete /mnt/storage/.hardware/3d-print/v2-red-V2-2201270017/files | ${pkgs.writeShellScript "voron2-red-sync" ''
function sync() {
rsync -avz --delete --exclude='.thumbs' /mnt/storage/.hardware/3d-print/v2-red-V2-2201270017/files/ pi@voron2-red:~/printer_data/gcodes/
if [[ $? -ne 0 ]]; then
echo "Sync failed"
fi
}
sync_pid=0
while read -r event; do
# Throttle syncing
if [ $sync_pid -ne 0 ]; then
kill $sync_pid 2>/dev/null || true
fi
# Schedule new sync
{ sleep 1; sync; } &
sync_pid=$!
done
''}
''
);
Restart = "always";
RestartSec = 1;
};
Install.WantedBy = [ "default.target" ];
};
systemd.user.timers.keepass-sync = {
Unit.Description = "Timer for KeePass sync";