Shutdown computer when sync is done

I sometimes have the same use case therefore included this into syncthingctl, e.g.:

syncthingctl wait-for-idle --dir foo && systemctl poweroff

This tool is developed within the Syncthing Tray project. The --help for wait-for-idle looks like this:

wait-for-idle, -w
  waits until the specified dirs/devs are idling
  --dir, -d [ID]
    specifies a directory by ID
  --dev [ID/name]
    specifies a device by ID or name
  --all-dirs
    applies the operation for all directories
  --all-devs
    applies the operation for all devices
  --at-least, -a [number]
    specifies for how many milliseconds Syncthing must idle (prevents exiting too early in case of flaky status)
  --timeout, -t [number]
    specifies how many milliseconds to wait at most

  example: syncthingctl wait-for-idle --timeout 1800000 --at-least 5000 && systemctl poweroff
           syncthingctl wait-for-idle --dir dir1 --dir dir2 --dev dev1 --dev dev2 --at-least 5000

Within this tool I use the regular REST API routes to query the initial state and the event API to be notified about changes. So the “expensive” routes are only used initially/once. I think that answers your question regarding the API usage.

syncthingctl is only about local completion (of course one can simply connect to a remote instance with the --url parameter). But for the UI I also implemented notifications for remote folders. When I remember correctly, I’ve used the db/completion route to query the remove completion and the RemoteIndexUpdated event to know when it might have changed and needs to be queries again.

4 Likes