We are all living in a technological wasteland.


NAS – Improving Owncloud speed


This part continues from the NAS – Part 4: Owncloud.

By default Owncloud can be a quite slow program. The setup which I have is no different. My setup grabs all the files from the network, causing a delay. To improve this I will be using the RAM disk suggested at: https://doc.owncloud.org/server/8.0/admin_manual/configuration_server/performance_tuning.html


In the past I mounted the network location directly to ‘/var/www/owncloud/’ but this isn’t possible anymore, as I want this folder to be used for the RAM disk.
Lets create a new mount point named ‘/media/network’ and change our fstab to reflect this change.

sudo mkdir -p /media/network
sudo nano /etc/fstab

Unmount and remount everything again and verify that it is mounted.

sudo umount /var/www/owncloud
sudo mount -a
df -h

Now we shall create the RAM disk. Verify that your installation is less than 192MB big (hint du).

sudo mount -t tmpfs -o size=192m tmpfs /var/www/owncloud

And add it to the fstab file.

sudo nano /etc/fstab
tmpfs       /var/www/owncloud tmpfs   nodev,nosuid,noexec,nodiratime,size=192M   0 0

To verify that it is working as desired, please reboot the machine and check if it is mounted. (We don’t want missing files)

sudo reboot
df -h

Now install unison, unison is the tool I will use to synchronize the files from the network disk to the ‘/var/www/owncloud’ directory. It has its quirks but in my case it works fine.

sudo apt-get install unison

Start by synchronizing our old files to the new RAM disk.

sudo unison /var/www/owncloud /media/network -ignore 'Path {data}' -force /media/network -confirmbigdel=false

Once this is done we need to create our synchronization scripts.

cd /home/owncloud

The first script will load the files from the network source. It will stop Apache2 whilst synchronizing the data to the ‘/war/www/owncloud’ folder. Also there is a force option to explicit force the download from the ‘/media/network’ location. If we don’t force this, unison will detect the newly created RAM disk as a newer version and will commence deleting the files we need to run Owncloud!
When everything is done, a tmp file will be written to flag that the unison cron job may synchronize files.

nano load-owncloud.sh
service apache2 stop
unison /var/www/owncloud /media/network -ignore 'Path {data}' -force /media/network -batch -confirmbigdel=false
ln -s /media/network/data /var/www/owncloud/data
chown -R www-data:www-data /var/www/owncloud
service apache2 start
touch /tmp/owncloud-initialized

The second job is our sync job. This is a two way sync, any changes made on the owncloud server and on the network source will be propagated to all.

nano sync-owncloud.sh
if [ -f $FILE ];
	unison /media/network /var/www/owncloud -batch -ignore 'Path {data}'

Make em executable.

chmod +x ./sync-owncloud.sh
chmod +x ./load-owncloud.sh

The last part of our scripting needs is the startup job. It’s pretty simple, this will just run our ‘load-owncloud.sh’ script.

sudo nano /etc/init/unison.conf
description "Owncloud File Sync"
author "Robbert Lambrechts"
env HOME=/home/owncloud
start on runlevel [2345]
pre-start script
    echo "Starts Owncloud sync..."
end script
post-stop script
    echo "Ends Owncloud sync..."
end script
exec /home/owncloud/load-owncloud.sh

Allow executing the startup script.

sudo chmod +x /etc/init/unison.conf

The last part is just allowing the sync job to run. This is done to apply changes.

sudo crontab -e
*/5 * * * * /home/owncloud/sync-owncloud.sh

That’s it. One fast Owncloud to serve files.

No Comments |