Linux SystemD Path
React to new files immediately
Section titled “React to new files immediately”A systemd path unit can watch a directory and trigger Connect whenever something changes. Here we move any new .zip in /data/ straight to the remote folder sftp://monitor02@10.0.0.24/target/ using an SSH key with a passphrase.
- Create an alias for the endpoint
$ connect alias addAlias name: sendEndpoint (no folder, e.g. sftp://host or s3://bucket): sftp://monitor02@10.0.0.24Change scheme-specific settings? (y/N) ySFTP private key path (optional): /apps/keys/id_ed25519SFTP key passphrase (optional): ****Connection test: OKAlias 'send' saved. You can now use it as @send/.. in commands.- Accept the host key and test the alias
$ connect ls @sendThe key (SHA256:v/goXq57T++lsDmeYduLCRJEUzEqf9u9OybWiHt3VRc) of 10.0.0.24:22 is unknown. Do you want to add this key to known_hosts (y/n): yName Size ModTimeincoming/ - 2025-02-10T09:13:39Z- Run the intended move command once
$ connect move --batch --no-color --parallel 3 \ /data/*.zip \ @send/target/2025/02/10 09:36:44 INFO Moving files to sftp://monitor02@10.0.0.24/target/2025/02/10 09:36:49 INFO Move finished – no more matches- Create the service unit that performs the move
$ systemctl --user edit --force --full send.service[Unit]Description=SFTP Send ServiceAfter=network-online.targetWants=network-online.target
[Service]ExecStart=/apps/connect move --batch --no-color --parallel 3 /data/*.zip @send/target/Reload systemd and test the service manually:
$ systemctl --user daemon-reload$ systemctl --user start send.service$ journalctl --user -eu send.service | tailFeb 10 10:11:37 arm connect[4036]: 2025/02/10 10:11:37 WARN No matching files for /data/*.zip- Create the path unit that watches
/data
$ systemctl --user edit --force --full send.path[Unit]Description=Watch /data for new files
[Path]PathModified=/dataUnit=send.service
[Install]WantedBy=default.target- Enable both units
$ systemctl --user daemon-reload$ systemctl --user enable --now send.pathCreated symlink /apps/.config/systemd/user/default.target.wants/send.path → /apps/.config/systemd/user/send.path.- Keep the user service alive after logout
$ sudo loginctl enable-linger $(whoami)- Review triggered runs
$ journalctl --user -eu send.service --since "1 hour ago"