Using Box with Subsonic Music Streamer

I’ve been a heavy user of Subsonic for the past five years.  I’ve used it primarily to stream music through the web interface and to my mobile devices.  It’s feature rich, provides transcoding, and supports almost every audio codec imaginable.  The most common setup for Subsonic is self-hosting on a desktop or dedicated server, but Subsonic also partners with several VPS providers for cloud-based hosting.  In my case, I host my own Subsonic server on a dedicated virtual machine.  For the longest time, I would upload music directly to the Subsonic server’s music directory.  The server would then update its internal database to make this music available.  This worked well, but it was difficult for others to contribute their music collection without knowledge or access to the server.  My goal was to find a way for users to upload pieces of their music collection to a location that Subsonic could also access.

Enter Box.  

Box is a powerful cloud-based collaboration platform targeted at small, medium, and enterprise organizations.  They also offer free consumer accounts.  What if Box could provide the audio files for Subsonic’s music library?

My initial thought was to use Box’s desktop sync client called Box Sync.  Box Sync synchronizes changes made to designated folders locally, making files available that others have contributed.  This would be a great solution if the Subsonic server was running on Windows or macOS.  Mine however runs on a lightweight CentOS 7 instance, and Box Sync is not available for Linux.  My next thought was to use the Box with WebDAV.  The Box instance could be mounted with davfs and then read by Subsonic.

WebDAV was fairly straightforward to configure on CentOS 7.  The davfs2 package was installed through the EPEL repo.

yum install -y epel-release
yum clean all
yum install -y davfs2

There were several modifications needed for davfs to mount.  First, the /etc/davfs/secrets file was changed to include the credentials for the Box account.

# WebDAV location, username, and password     [email protected]     mypassword

The /etc/davfs2/davfs2.conf file was also changed to disable file locks.

use_locks 0

I created a directory under /mnt/box-dav that will serve as the mount point.  The final step was to edit /etc/fstab to automatically mount the Box WebDAV instance.  The following modification was made to /etc/fstab.   /mnt/box-dav   davfs  defaults  0 0

After running the mount -a command, the instance mounted successfully.

The final step was adding the folders in Subsonic.

After starting the media folder scan to rebuild the database, I noticed an extreme performance degradation in populating the media library.  It appeared that the I/O performance over WebDAV was not adequate for such a large college of music.  The initial scan took over 4 hours to complete.  I decided to take a different approach and synchronize the files locally from WebDAV.  By doing this, the subsonic service would have access to media at higher I/O speeds, but the users would still have the benefit of using Box to build the media library.

I wrote a quick script using rsync to synchronize a local directory from the mounted WebDAV instance on Box.  I then updated the Subsonic media directories to point to the local directory.

  • /mnt/box – the local copy of the media
  • /mnt/box-dav – the WebDAV instance from Box

To ensure that the sync happened regularly, the script was moved to /usr/sbin and added to the crontab to run nightly at 2am.

* 2 * * *    /usr/sbin/boxsync

Boxsync Script

For reference, I’ve provided the script I used to synchronize the WebDAV directory with the local media directory.  The code is available on my GitHub profile.

Additional Reading

Does Box support WebDAV? – The Box Community

Jimmy McNatt
Jimmy McNatt
Articles: 38