1

I'd like to use Unison to sync a directory between my desktop computer and a container that lives in the cloud. I have this kind of working with Unison, but the problem I'm seeing is that every time I spin up the container, it can have a different hostname and IP number, and sshd will be running on a different port number.

To make this mostly transparent to me, every time I spin up the container, I edit my ~/.ssh/config file like so:

Host pod
   User root
   Hostname 184.26.5.182
   Port 10666

I replace the IP number and port number accordingly.

Once I've done this, I can log into the container using ssh pod, etc. I can run scripts that rsync stuff around with no problem, even though they have the host alias "pod" hardwired into them. (If I knew how to make rsync do a bidirectional sync with deletions, then I'd just use that, but I'm pretty sure that that is not possible.)

My Unison config file looks like this:

root = /Users/me/path/to/dir
root = ssh://pod//path/to/dir
 
ignore = Path subdir1
ignore = Path subdir2

Unfortunately, this does not work great because every time I spin up the container, I get a different port number (the IP number doesn't usually change), and Unison considers this to be a fresh sync. Which is not at all what I want.

Is there a way to tell Unison to ignore the fact that the remote container seems to have changed to a different computer, and to just trust that my "pod" host alias can be relied on for host identity?

1 Answer 1

1

I've determined an answer to my question, but it's a bit of a pain.

First, I changed the entry in my local ~/.ssh/config file so that it looks like this:

Host pod
   User root
   SetEnv UNISONLOCALHOSTNAME=pod
   Hostname 184.26.5.182
   Port 10666

That's very easy, of course. But this won't work, however, unless sshd is configured in the container to allow the incoming ssh client to perform this SetEnv command. sshd is not configured to allow this by default. Consequently, I'll have to write a script that I can invoke on the container every time I spin it up, which does the following before I run unison on my desktop computer:

  1. Add the line AcceptEnv UNISONLOCALHOSTNAME onto the end of the container's /etc/ssh/sshd_config.
  2. Tell the container's sshd to reload its config file by doing
kill -HUP `cat /var/run/sshd.pid`

ALTERNATIVELY:

And a bit more easily, I can just have a script modify /root/.bashrc in the container to have

export UNISONLOCALHOSTNAME=pod

placed at the top of /root/.bashrc. (It wasn't working when I placed it at the bottom of the .bashrc because it turns out that there is code in the .bashrc that exits early if the shell is not interactive.)

Unfortunately, I can't just edit the .bashrc once and be done with it since the root filesystem is reinitialized every time the container is started up. So this rewriting of /root/.bashrc has to either be done by a script that I either keep on the persistent filesystem that the cloud service provides. Or I can do the editing of the container's .bashrc via a local script on my desktop that uses ssh and scp to make the change.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.