0

I have a shared cache on a remote server that multiple clients are reading and writing to, so I need to synchronize access to this cache. I imagine I could:

  1. SSH into the remote and acquire a flock on the server
  2. Push the update to the server (rsync)
  3. Release the flock

The flock itself is working, but in order for the entire thing to work I need a way to start a process on the remote, that can acquire and hold the lock while I update the cache from the client. The flock should then be released from client in 3. or if the connection to the client is lost. Any ideas for how to accomplish this?

Btw: In my current setup it is not possible for the server to connect to the client and 'pull' the update over SSH allowing everything to be handled in a single script executed on the remote.

1 Answer 1

0

Thought I would just share my solution:

rsync -r --rsync-path="flock $dst/lockfile rsync" $src/ $server:$dst

So using --rsync-path I acquire a lock on the remote before starting the rsync server. If multiple clients are doing this simultaneously the they will have to wait for the file lock to be available before rsync'ing.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .