I sometimes need to copy config files between my main server and Raspberry Pi. Since I implemented Linux cluster between them, it will be a bigger and bigger requirement for me. I have figured out a solution, which seems working, I share it.
What’s the plan?
It would be very handy, if I would use a shared folder between my servers, so I can easily store and propagate the changes. For file sharing, I use Samba. Earlier I used samba with my other devices what I use daily drive (Windows PC, iPad, iPhone). And now, for this “shared configuration folder” it could also be used.
First try!
As mostly, I am starting from the easiest thing. My first idea was to simple: mount it after network is up. I tried to archive it with a new mount in systemd:
[Unit] Description=Mount server shared Samba share Requires=network.target After=network.target [Mount] What=//atihome.local/shared_work_ati Where=/mnt/shared_work_ati Options=credentials=/root/.atismbcred,uid=pi,gid=pi,file_mode=0664 Type=cifs LazyUnmount=true ForceUnmount=true [Install] WantedBy=multi-user.target
System component, systemd will handle the mount point. What
parameter is the device what we want to mount. Where
is a file path where we want to mount the devices. Options
is where we provide the security settings for Samba connection. By using file_mode=0664
I give read-write permission for pi user and group and read only for the others. Executing scripts from this point is not allowed for nobody.
Service worked, everything looked nice. But during testing I have found a problem. When I stopped my main server (without unmount file system on Raspberry Pi), some command has become slow, for example df -h
. The reason was that it tried to reach my main server (atihome), but it can’t. And timeout was more seconds. I did not like it, because I prefer is everything is smooth.
What can I do?
I was thinking on some idea:
- Set a timer which checks atihome samba service regularly and execute unmount or mount command accordingly: it looks fine, but I don’t want to run this check every 5-10 seconds (I also do not like when something is not fixed/changed immediately when needed)
- Next idea: timer runs on Pi, and when Samba is started/stopped on atihome I send a signal to Pi to act accordingly
Second solution I liked. I was begin to thinking how to implement it, then I thought I could use cluster resource manager to handle it. Because that is already checking connectivity, I just need to configure it!
My final solution
First, I disabled Samba services from systemd control: systemctl disable samba
. When it was I put some new line into my crm
configuration:
primitive SambaAti service:smbd \ op start timeout=100s interval=0 \ op monitor interval=30s timeout=100s \ op_params restart=on-failure \ meta target-role=Started primitive SambaWorkShared systemd:mnt-shared_work_ati.mount \ op start timeout=100s interval=0 \ op monitor timeout=100s interval=30s \ op_params restart=on-failure \ meta target-role=Started location SambaAtiDisLocation SambaAti -inf: pihome location SambaAtiLocation SambaAti inf: atihome location SambaWorkSharedDisLocation SambaWorkShared -inf: atihome location SambaWorkSharedLocation SambaWorkShared inf: pihome order SambaWorkSharedOrder Mandatory: SambaAti SambaWorkShared
By the lines above, I told the crm
that:
- I defined Samba service which is running on atihome as SambaAti resource
- I defined mount/unmount service which is running on pihome as SambaWorkShared resource
- I defined locations: they never run on another node even when the main location is down (
-inf
can disable location) - Finaly, I set a start order: mount will be executed after Samba is started atihome; when Samba is not running then execute unmount (lazy + force way)
This is does exactly what I want!
- When Pi is down, Samba still running on atihome because I can use it from other devices
- When atihome is down, unmount happen on Pi, so commands like
df
will not be slow as waiting for connection timeout - When atihome available again, it will mount the drive on Pi
Final words
It is might not the best solution, but it works for me as I want! Better solution would be, if would have a separated NAS or storage box what both server reach and I could implement a Samba cluster. But I don’t have such things (so far). So for now, it works perfectly as I want: no need to wait, seems handy and comfortable, no compromises against me.