Difference between revisions of "Firefox Sync Server"

From ArchWiki
Jump to: navigation, search
(Automatic Startup of the Server)
(Add database configuration paragraph)
 
(42 intermediate revisions by 15 users not shown)
Line 1: Line 1:
[[Category:Web Server]]
+
[[Category:Synchronization]]
This page is about special operations required in order to install Mozilla Sync Server.
+
[[ja:‎Firefox Sync Server]]
 +
[https://www.mozilla.org/en-US/firefox/features/sync/ Firefox Sync] is a protocol developed by Mozilla to synchronize a browser configuration and profile between different Firefox instances which could run on different platforms (e.g. mobile and desktop). In a default configuration, the user data is encrypted and stored on Mozilla servers.
  
Newer versions of Mozilla Firefox feature bookmarks, passwords, settings and browsing history synchronization between all your computers and devices. Mozilla Foundation provides a public Sync server, but you can host your own one if you want.
+
This page details on how to setup an own Firefox Sync Server and how to configure the client software to use it.
==Prerequisites==
+
== Server setup ==
===Dependencies===
 
Before proceeding, you need to [[pacman|install]] {{pkg|python2}}, {{pkg|python2-virtualenv}}, {{pkg|sqlite3}}, {{pkg|mercurial}} and {{pkg|make}}, all available in the [[official repositories]].
 
===Accessibility===
 
If you intend to use your server with itinerant clients, you should install it on an Internet reachable computer.
 
===Administration Rights===
 
All installation instructions are commands relying on the superuser privileges, so open a terminal and type:
 
{{bc|
 
$ su -
 
Password:
 
#
 
}}
 
  
==Installation==
+
=== Installation ===
Mozilla Sync Server depends on Python 2 during installation. Arch Linux provides Python 3 as default Python version so there are special tweaks needed before running Mozilla Sync Server setup.
 
Setup process creates an isolated Python environment in which all necessary dependencies are downloaded and installed. Afterwards, running the server only relies on the isolated Python environment, independently of the system-wide Python.
 
===Python preparation===
 
Mozilla Sync Server setup needs Python 2.6 or newer. In default configuration, {{ic|/usr/bin/python}} is a symbolic link to {{ic|/usr/bin/python3}} whereas Python 2 is {{ic|/usr/bin/python2}}.
 
  
Before running setup, we must check the link and change it if necessary:
+
{{AUR|mozilla-firefox-sync-server}} is available in the [[AUR]].
{{bc|
 
# cd /usr/bin
 
# ls -l python
 
  
    lrwxrwxrwx 1 root root 7  5 sept. 07:04 python -> python3
+
=== Configuration ===
  
# ls -l virtualenv
+
One file is available to configure a firefox sync server: {{ic|/etc/webapps/mozilla-firefox-sync-server/syncserver.ini}}. Most options are explained clearly in the [http://docs.services.mozilla.com/howtos/run-sync-1.5.html official documentation]. You might want to change to variables, the accepted domain name ({{ic|public_url}}) and the database backend ({{ic|sqluri}}):
  
    ls: cannot access virtualenv: No such file or directory
+
{{hc|/etc/webapps/mozilla-firefox-sync-server/syncserver.ini|<nowiki>
 +
public_url = https://sync.example.com
 +
sqluri = sqlite:////var/lib/mozilla-firefox-sync-server/syncserver.db
 +
</nowiki>}}
  
# ln -sf python2 python
+
==== Database ====
# ln -sf virtualenv2 virtualenv
 
}}
 
  
===Setup===
+
Other databases can be used as backend for the firefox sync server such as [[MySQL]] or [[PostgreSQL]] instead of [[SQLite]]. In order to achieve this it's necesserary to add python packages via pip.
Installation instructions:
 
{{bc|
 
# mkdir -p /opt/weave
 
# cd /opt/weave
 
# hg clone https://hg.mozilla.org/services/server-full
 
  
      ... source repository cloning messages ...
+
For MySQL {{bc|/usr/share/webapps/mozilla-firefox-sync-server/local/bin/pip install PyMySQL}}
 +
For PostgreSQL {{bc|/usr/share/webapps/mozilla-firefox-sync-server/local/bin/pip install psycopg2}}
  
# cd server-full
+
Then appropriate databases and users must be created in the database engine that will be used.
# make build
 
  
      ... many build messages, including harmless warnings ...
+
The syncserver.ini file should also be modified to reflect the change of database and it uses the SQLAlchemy syntax.
  
      ... end of the successful build messages:
+
For MySQL {{hc|/etc/webapps/mozilla-firefox-sync-server/syncserver.ini|<nowiki>
 +
[syncserver]
 +
sqluri = pymysql://username:password@db.example.com/sync
 +
</nowiki>}}
  
Building the app
+
For PostgreSQL {{hc|/etc/webapps/mozilla-firefox-sync-server/syncserver.ini|<nowiki>
  Checking the environ  [ok]
+
[syncserver]
  Updating the repo  [ok]
+
sqluri = postgresql://username:password@db.example.com/sync
  Building Services dependencies
+
</nowiki>}}
    Getting server-core    [ok]
 
    Getting server-reg    [ok]
 
    Getting server-storage    [ok]  [ok]
 
  Building External dependencies  [ok]
 
  Now building the app itself  [ok]
 
[done]
 
  
}}
+
=== Example nginx and uwsgi setup ===
  
Check the end of the build messages, they should state "[done]". Otherwise, look at the first error messages, they give you hints on the problem and how to solve it.
+
It is recommended to serve the firefox sync server with uwsgi in a production environement. In this case you have to install {{Pkg|uwsgi-plugin-python2}}. Create following uwsgi config file:
  
===Python initial state restoration===
+
{{hc|/etc/uwsgi/mozilla-firefox-sync-server.ini|<nowiki>
Once the build is finished, restore the links in {{ic|/usr/bin}} to their original state.
+
[uwsgi]
{{bc|
+
socket = /run/uwsgi/%n.sock
# cd /usr/bin
+
uid = ffsync
# ln -sf python3 python
+
gid = ffsync
# rm -f virtualenv
+
chdir = /usr/share/webapps/mozilla-firefox-sync-server
}}
+
master = true
 +
plugins = python2
 +
file = syncserver.wsgi
 +
</nowiki>}}
  
==Configuration==
+
[[Enable]] and [[start]] the {{ic|uwsgi@mozilla\\x2dfirefox\\x2dsync\\x2dserver }} service.
===Server-side configuration files===
 
Configuration files are used to define where databases and logs will be created.
 
We will place databases in {{ic|/opt/weave/data}} and log files in {{ic|/var/log/weave}}, so we must create the directories.
 
# mkdir /opt/weave/data /var/log/weave
 
  
At least two configuration files must be changed in {{ic|/opt/weave/server-full}} in order to reflect these choices: {{ic|development.ini}} and {{ic|etc/sync.conf}}.
+
An example [[Nginx]] configuration looks something like this:
  
In {{ic|development.ini}}, locate the line:
+
{{hc|/etc/nginx/sites-enabled/sync.example.com|<nowiki>
{{bc|1=
+
server {
args = ('/tmp/sync-error.log',)
+
  server_name sync.example.com;
}}
+
  access_log /var/log/nginx/sync.example.com.access.log;
and change it to:
+
  error_log /var/log/nginx/sync.example.com.error.log info;
{{bc|1=
+
  server_tokens off;
args = ('/var/log/weave/sync-error.log',)
 
}}
 
  
In {{ic|etc/sync.conf}}, locate the line:
+
  client_max_body_size 15M;
{{bc|1=
 
sqluri = sqlite:////tmp/test.db
 
}}
 
and change it to:
 
{{bc|1=
 
sqluri = sqlite:////opt/weave/data/sync.db
 
}}
 
This statement appears twice in the file, both should be modified.
 
  
Bump the disk quota from 5 to 25 MB:
+
  location / {
{{bc|1=
+
    include uwsgi_params;
quota_size = 25600
+
    uwsgi_pass unix:/run/uwsgi/mozilla-firefox-sync-server.sock;
}}
+
  }
The fallback node URL must reflect the server's hostname (here {{ic|server-name.domain-name}}).
+
}
Change:
+
</nowiki>}}
{{bc|1=
 
fallback_node = <nowiki>http://localhost:5000/</nowiki>
 
}}
 
to:
 
{{bc|1=
 
fallback_node = <nowiki>http://server-name.domain-name:5000/</nowiki>
 
}}
 
  
===Unprivileged User===
+
== Client configuration ==
It is a good practice to run daemons as an unprivileged user. Create the group {{ic|weave}} and the user {{ic|sync}} for that purpose:
 
{{bc|
 
# groupadd weave
 
# useradd -d /opt/weave -g weave -r -s /bin/bash sync
 
}}
 
This new user must have read and write access on every file in {{ic|/opt/weave}} and {{ic|/var/log/weave}}
 
# chown -R sync:weave /opt/weave/*
 
# chown -R sync:weave /var/log/weave
 
  
===Automatic Startup of the Server===
+
{{Note|Since version 1.5 of the protocol, a [https://www.mozilla.org/en-US/firefox/accounts/ Firefox Account] is required in order to use the synchronization service.}}
In order to make the Sync Server start automatically at boot-time, create a startup script:
+
To configure desktop Firefox to talk to your new Sync server, go to {{ic|about:config}}, search for {{ic|identity.sync.tokenserver.uri}} and change its value to the URL of your server with a path of {{ic|token/1.0/sync/1.5}}:
{{hc|
+
{{bc|1=
/etc/rc.d/mozillaweave|<nowiki>
+
identity.sync.tokenserver.uri: <nowiki>http://example.com/ffsync/token/1.0/sync/1.5</nowiki>
#!/bin/bash
 
 
 
RUNDIR=/var/run/weave
 
DAEMON=/opt/weave/bin/python
 
PIDFILE=/var/run/weave.pid
 
MESSAGELOG=/var/log/weave/sync-messages.log
 
 
 
. /etc/rc.conf
 
. /etc/rc.d/functions
 
 
 
PID=`pidof -x -o %PPID paster`
 
case "$1" in
 
  start)
 
    stat_busy "Starting Mozilla Sync Server"
 
    [ -d $RUNDIR ] || mkdir $RUNDIR
 
    [ -z "$PID" ] && su sync -c "cd /opt/weave/server-full && bin/paster serve development.ini &>$MESSAGELOG &"
 
    if [ $? -gt 0 ]; then
 
      stat_fail
 
    else
 
      PID=`pidof -x -o %PPID paster`
 
      echo $PID >$PIDFILE
 
      add_daemon weave
 
      stat_done
 
    fi
 
    ;;
 
  stop)
 
    stat_busy "Stopping Mozilla Sync Server"
 
    [ ! -z "$PID" ]  && kill $PID &>/dev/null
 
    if [ $? -gt 0 ]; then
 
      stat_fail
 
    else
 
      rm_daemon weave
 
      stat_done
 
    fi
 
    ;;
 
  restart)
 
    $0 stop
 
    $0 start
 
    ;;
 
  *)
 
    echo "usage: $0 {start|stop|restart}
 
esac
 
exit 0
 
</nowiki>
 
}}
 
The script must have execution rights:
 
# chmod 755 /etc/rc.d/mozillaweave
 
Start the Sync Server at boot by including {{ic|mozillaweave}} in the [[Daemon]] list. It depends on the network so it should be placed accordingly.
 
 
 
For systemd:
 
{{hc|
 
/etc/systemd/system/mozillaweave.service|<nowiki>
 
[Unit]
 
Description=Mozilla Weave
 
After=network.target
 
 
 
[Service]
 
Type=simple
 
User=sync
 
WorkingDirectory=/opt/weave/server-full
 
ExecStart=/opt/weave/server-full/bin/python2 /opt/weave/server-full/bin/paster serve /opt/weave/server-full/development.ini
 
StandardOutput=/var/log/weave/sync-messages.log
 
 
 
[Install]
 
WantedBy=multi-user.target
 
Alias=mozillaweave.service
 
</nowiki>
 
}}
 
 
 
Test start the server using:
 
{{bc|
 
# systemctl start mozillaweave
 
# systemctl status mozillaweave
 
}}
 
 
 
Set the Sync Server to start at boot with:
 
{{bc|
 
# systemctl enable mozillaweave
 
 
}}
 
}}
 +
{{Tip| Enter {{ic|about:sync-log}} in the Firefox URL bar to get a list of logs related to Firefox Sync.}}
  
===Client-side configuration===
+
== See also ==
Use the Sync Configuration Wizard in Firefox' Settings to create a new account on the server. Don't forget to choose "Custom server..." in the list, and input the server address: {{ic|<nowiki>http://server-name.domain-name:5000/</nowiki>}}
 
  
The "Advanced Settings" button allows fine tuning of the synchronized elements list, and the definition of the client hostname.
+
* [http://docs.services.mozilla.com/howtos/run-sync.html Official Mozilla Firefox Sync Server Howto]
==See also==
+
* [http://alien.slackbook.org/blog/setting-up-your-own-mozilla-sync-server/ Howto with Apache support by Eric Hameleers]
* [http://docs.services.mozilla.com/howtos/run-sync.html Mozilla Sync Server Howto]
+
* [https://tim.siosm.fr/blog/2012/12/11/firefox-sync-nginx-systemd/ Howto with nginx and systemd support by Timothée Ravier]
* [http://alien.slackbook.org/blog/setting-up-your-own-mozilla-sync-server/ Great tutorial, by Eric Hameleers]
+
* [http://amnesiak.org/blog/mozilla-sync-server-with-nginx.html Howto with nginx support]
 +
* [http://terminal28.com/how-to-install-and-configure-own-firefox-sync-server-weave-debian/ Howto using MySQL]
 +
* [[OwnCloud]] has mozilla sync server application

Latest revision as of 09:56, 18 May 2018

Firefox Sync is a protocol developed by Mozilla to synchronize a browser configuration and profile between different Firefox instances which could run on different platforms (e.g. mobile and desktop). In a default configuration, the user data is encrypted and stored on Mozilla servers.

This page details on how to setup an own Firefox Sync Server and how to configure the client software to use it.

Server setup

Installation

mozilla-firefox-sync-serverAUR is available in the AUR.

Configuration

One file is available to configure a firefox sync server: /etc/webapps/mozilla-firefox-sync-server/syncserver.ini. Most options are explained clearly in the official documentation. You might want to change to variables, the accepted domain name (public_url) and the database backend (sqluri):

/etc/webapps/mozilla-firefox-sync-server/syncserver.ini
public_url = https://sync.example.com
sqluri = sqlite:////var/lib/mozilla-firefox-sync-server/syncserver.db

Database

Other databases can be used as backend for the firefox sync server such as MySQL or PostgreSQL instead of SQLite. In order to achieve this it's necesserary to add python packages via pip.

For MySQL
/usr/share/webapps/mozilla-firefox-sync-server/local/bin/pip install PyMySQL
For PostgreSQL
/usr/share/webapps/mozilla-firefox-sync-server/local/bin/pip install psycopg2

Then appropriate databases and users must be created in the database engine that will be used.

The syncserver.ini file should also be modified to reflect the change of database and it uses the SQLAlchemy syntax.

For MySQL
/etc/webapps/mozilla-firefox-sync-server/syncserver.ini
[syncserver]
sqluri = pymysql://username:password@db.example.com/sync
For PostgreSQL
/etc/webapps/mozilla-firefox-sync-server/syncserver.ini
[syncserver]
sqluri = postgresql://username:password@db.example.com/sync

Example nginx and uwsgi setup

It is recommended to serve the firefox sync server with uwsgi in a production environement. In this case you have to install uwsgi-plugin-python2. Create following uwsgi config file:

/etc/uwsgi/mozilla-firefox-sync-server.ini
[uwsgi]
socket = /run/uwsgi/%n.sock
uid = ffsync
gid = ffsync
chdir = /usr/share/webapps/mozilla-firefox-sync-server
master = true
plugins = python2
file = syncserver.wsgi

Enable and start the uwsgi@mozilla\\x2dfirefox\\x2dsync\\x2dserver service.

An example Nginx configuration looks something like this:

/etc/nginx/sites-enabled/sync.example.com
server {
  server_name sync.example.com;
  access_log /var/log/nginx/sync.example.com.access.log;
  error_log /var/log/nginx/sync.example.com.error.log info;
  server_tokens off;

  client_max_body_size 15M;

  location / {
    include uwsgi_params;
    uwsgi_pass unix:/run/uwsgi/mozilla-firefox-sync-server.sock;
  }
}

Client configuration

Note: Since version 1.5 of the protocol, a Firefox Account is required in order to use the synchronization service.

To configure desktop Firefox to talk to your new Sync server, go to about:config, search for identity.sync.tokenserver.uri and change its value to the URL of your server with a path of token/1.0/sync/1.5:

identity.sync.tokenserver.uri: http://example.com/ffsync/token/1.0/sync/1.5
Tip: Enter about:sync-log in the Firefox URL bar to get a list of logs related to Firefox Sync.

See also