-
-
Notifications
You must be signed in to change notification settings - Fork 5
Watch Mode
Watch mode runs kei as a long-lived process, repeating the download cycle at a fixed interval.
# Sync every hour
kei sync -u my@email.address -d /photos --watch-with-interval 3600After completing a full download pass (enumerate → filter → download), the process sleeps for the specified number of seconds, then starts a new pass. This repeats indefinitely until stopped by a shutdown signal (Ctrl+C, SIGTERM, or SIGHUP).
Each cycle checks for changes using a stored CloudKit syncToken. If nothing changed since the last cycle, the check completes in 1-2 API calls and the cycle ends immediately. When changes are detected, only the delta is downloaded. On the first cycle (no stored token), a full enumeration is performed. See State Tracking for details.
The minimum interval is 60 seconds. Values below 60 are rejected at startup. Apple rate-limits aggressively, and short intervals risk account lockouts.
Sending Ctrl+C, SIGTERM, or SIGHUP during a watch mode cycle will:
- Finish any in-flight downloads (partial
.kei-tmpfiles are kept for resume) - Skip remaining queued downloads
- Exit cleanly
If in-flight downloads don't finish within 30 seconds, they're cancelled and the process exits. If the signal arrives during the sleep interval between cycles, the sleep is interrupted and the process exits immediately. A second signal at any point force-exits the process.
Albums are re-resolved at the start of each watch cycle. If you create a new album in iCloud, it will be discovered on the next cycle without restarting the daemon.
When a download cycle ends with partial failures (some files downloaded, some failed), watch mode logs a warning and continues to the next cycle instead of exiting. Transient failures are expected in long-running sessions - the next cycle retries failed assets automatically via the state database.
Only a complete failure (no files downloaded at all) causes the daemon to exit.
On Linux, use --notify-systemd to integrate with systemd's service manager. kei sends:
-
READY=1after authentication completes -
STATUS=with cycle progress updates -
STOPPING=1on shutdown -
WATCHDOG=1heartbeats (ifWatchdogSec=is configured)
Use --pid-file to write a PID file for service managers that need it.
[Unit]
Description=kei photo sync
After=network-online.target
[Service]
Type=notify
ExecStart=/usr/local/bin/kei sync \
--username my@email.address \
--download-dir /photos \
--watch-with-interval 3600 \
--notify-systemd \
--pid-file /run/kei.pid
Restart=on-failure
WatchdogSec=7200
[Install]
WantedBy=multi-user.target