Setup your own Firefox Sync Server
As most people know I hate using someone else’s service when I can host my own and since I’ve started using Firefox for Android that’s no exception.
Firefox allows you to sync your preferences, bookmarks and add-on settings between devices using the Firefox Sync Service, but they default servers are hosted by Mozilla. This isn’t a problem for me as they encrypt all data in the client before its transmitted to their servers, and if you don’t trust the client then there are bigger problems. Still I like to ‘roll-my-own’ when ever I can and Mozilla have made running you own sync server very easy.
The instructions bellow are based on my current install. Which is Ubuntu 12.04.1 LTS, MySQL and Apache2. These steps worked with out any problems for me – please let me know in the comments how you get on and if you find any problems or have to take any additional steps I missed out.
As yet Mozilla don’t release any binary packages for their server, so to install one what I’ll be doing it checking out the latest release from their repository and building it in-place
Prerequisites These are the things you’ll need
Like most software, the server is made up of several components that all work together to form the final application. In-order for them to work you will need to make sure your system has these installed, or install them now:
- Python 2.6 – http://python.org/download/releases/2.6.6
- Virtualenv – http://pypi.python.org/pypi/virtualenv
To install these on my Ubuntu machine I just make the this request of Apt-get:
[~]$ sudo apt-get install mercurial python-dev python-virtualenv sqlite3
The Build Use the source
Now that your machine is ready you need to get a copy of the latest source code from https://hg.mozilla.org/services/server-full:
[~]$ hg clone https://hg.mozilla.org/services/server-full [~]$ cd server-full
No we have the source we can use the build command to make an Python environment isolated from the rest of the system. It’s into this environment all the required dependences are installed :
[~/server-full]$ make build
In a unique step for I even got make to ran the testsuite on the compiled source:
[~/server-full]$ make test
In the end this worked out to my advantage because it found a missing dependency. Using the pip command I installed pysqlite into the new python environment:
[~/server-full]$ ./bin/pip install pysqlite
Running test again produced no error so it’s safe to move onto the configuration
The Configuration Make it work
To configure the server you only need to edit the ini-like setup file “
./etc/sync.conf“. The is well commented and you will probably be able to make seance of it. In the most part the defaults worked fine for me, but you do have to change a few things.
The first is the fallback_node URL. This is the client visible URL of your service and make sure node-assignment and user registration works correctly. The default value has port 5000 specified in the URL. This is in-case you are running in standalone server mode, I am not as I will be putting Apache in front of the server so I just took it out:
[~/server-full]$ nano -w etc/sync.conf ... [nodes] fallback_node = http://yoursyncserver.com ...
Out-the-box the server will use sqlite files for the user and storage database. You’ll see in the configuration file these are being stored in “/tmp” this is obliviously an terrible idea for a production server, so next well move them to a more appropriate place:
[~/server-full]$ nano -w etc/sync.conf ... [storage] sqluri = sqlite:////path/to/your/database.db [auth] sqluri = sqlite:////path/to/your/database.db ...
Apache Running behind a Web Server
At this point the server already has a server built in which I’ve not talked about, partly this is because while it is good testing it should not be used in a production environment but mostly its because I never had any cause to run it.
For production server you will need a web server which is compatible with WSGI protocal. These include, but are probably not limited to:
- Apache – Combined with mod_wsgi
- NGinx – With Gunicorn or uWSGI
- lighttpd – With flup, using the fcgi or scgi protocol
I will be talking about the first option as my server was already configured for it.
Create a new Apache configuration file for your server, bellow is an example of the configuration I used:
ServerName yoursyncserver.com DocumentRoot ~/server-full WSGIProcessGroup sync WSGIDaemonProcess sync user=www-data group=www-data processes=2 threads=25 WSGIPassAuthorization On WSGIScriptAlias / ~/server-full/sync.wsgi
Order deny,allow Allow from all
That should be you done. Just reload your Apache server to activate the new host and start playing:
[~/server-full]$ sudo service apache reload
Security & User Registration It’s not a dirty word you know!
After installation and Apache setup your ready to rock and or roll! However in the default configuration the server support new user registration using the Firefox built in interface. Now unless you are going to make your server public to the world it’s a good idea to disable this after you have setup your own Firefox instance:
[~/server-full]$ nano -w etc/sync.conf ... [auth] allow_new_users = false ...