ownCloud davfs automount on Linux
One day I decided to throw away Dropbox and Google Drive and start using ownCloud. It was great decision, really, because LAN sync between all local machines is fast as kid after first kari. Whole thing runs on my Raspberry Pi 2 and it works really well. But it was local only. Since I am sitting behind mean O2 router with no possibility of port forwarding, I was trapped within LAN (hush, VPN is hell on earth).
Decision was made. I need utilize remote server. I am paying hosting at Endora.cz so I tried to deploy it here. After some fighting I got it to work, so I had two clouds. Local, fast and quite big and remote, slow and small. Target is clear. Get some data to Internet. Not all of them, but some. Something like Public folder at Dropbox or something like that. Get them acessible from everywhere. But how to manage sync between those clouds? On client side? No, just no. It is just stupid idea. I want to have it autonomous. And beside that, local cloud should be master one. So everythng is in local one and some selected folders will be send to remote. And worker will be my fellow Raspberry Pi.
Most accessible way is usage of WebDAV protocol, becuse my Raspberry Pi is running headless so desktop client is out of scope. On linux is filesystem named davfs which is able to connect via WebDAV to server. Cool. Now is time to connect it together.
Bigger part of work is described here. In there is nice how-to get davfs2 to work. I have two notes to it:
- correct path to secrets file is this:
~/.davfs2/secrets. On my box it made it by itself after first try to connect, so you can try it too. Just mount your sharepoint as user, fill in credentials and voiala, configuration is here.
- I am not sure if I were just unlucky, but I needed to put TAB between address, login and password. Not SPACE.
Well, and now comes tricky part. How to get it to work automatically? We are going to use
/etc/init.d/ bootup scripts. Let's make resume, what we wants.
- boot up box, and let it mount davfs automatically
- that means wait for network and local drives to init, right?
- also we want to get this thing working only during normal run.
- and we don't want to write down password and login.
In system is one user, who don't need to write passwords. Mighty root. So, why not use this command?
su -c "mount /mnt/knock-knock-cloud/" -s /bin/bash rain
/mnt/knock-knock-cloud/ is my mount point and
rain is my login. Call it as root and it runs mount as me (rain). Pretty neat, huh?
Now put it all together. We need to make boot-up script. Navigate to
/etc/init.d/ and creates here some script (in my case it is
mount-cloud.sh). Set it as executable (so rights
+x) and fill it with this:
1 2 3 4 5 6 7 8 9 10 11 12
#!/bin/sh ### BEGIN INIT INFO # Provides: mount-cloud # Required-Start: $network $local_fs $syslog # Required-Stop: $network $local_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Mounts /mnt/knock-knock-cloud via user rain # Description: Utilizes secrets file at rain's home for mouting ### END INIT INFO su -c "mount /mnt/knock-knock-cloud/" -s /bin/bash rain
Because I am using Debian, I must add INIT INFO section. Nice description is here. It is necessary to run. Without it Debian will skip it. First part is script name, then what is needed to run. You can see there is wildcard for network, local filesystem and we want to have syslog alive. Next section are Start and Stop runlevels. Debian have same meaning for runlevel 2-5 (normal multiuser run) so that is what we want. Otherwise, stop it.
Thats all. After this info is script itself. In our case it is only command mentioned before.
Now we need to register this script to system, so run this command:
sudo update-rc.d mount-cloud.sh defaults
and try to reboot. It should mount your davfs during bootup.
That's it. Next part will be to sync them. But not in this article.