Difference between revisions of "Mozilla Firefox Sync Server"

From ArchWiki
Jump to: navigation, search
m (Installing Mozilla Sync Server)
(See also)
(23 intermediate revisions by 7 users not shown)
Line 1: Line 1:
[[Category:Networking (English)]]
+
[[Category:Web Server]]
{{i18n|Mozilla Sync Server}}
+
{{stub}}
+
 
+
 
This page is about special operations required in order to install Mozilla Sync Server.
 
This page is about special operations required in order to install Mozilla Sync Server.
  
Newer versions of Mozilla Firefox feature bookmarks, passwords 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.
+
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.
  
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.
+
This article describes how to install it manually. Note that there is also an AUR package for it: {{aur|mozilla-firefox-sync-server-hg}}
  
 
==Prerequisites==
 
==Prerequisites==
 
===Dependencies===
 
===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]].
+
Before proceeding, you need to [[pacman|install]] {{pkg|python2}}, {{pkg|python2-virtualenv}}, {{pkg|sqlite}}, {{pkg|mercurial}} and {{pkg|make}}, all available in the [[official repositories]].
 
===Accessibility===
 
===Accessibility===
 
If you intend to use your server with itinerant clients, you should install it on an Internet reachable computer.
 
If you intend to use your server with itinerant clients, you should install it on an Internet reachable computer.
 
 
===Administration Rights===
 
===Administration Rights===
 
All installation instructions are commands relying on the superuser privileges, so open a terminal and type:
 
All installation instructions are commands relying on the superuser privileges, so open a terminal and type:
Line 23: Line 19:
 
}}
 
}}
  
==Preparing Python==
+
==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}}.
 
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}}.
  
Line 32: Line 31:
  
 
     lrwxrwxrwx 1 root root 7  5 sept. 07:04 python -> python3
 
     lrwxrwxrwx 1 root root 7  5 sept. 07:04 python -> python3
 +
 +
# ls -l virtualenv
 +
 +
    ls: cannot access virtualenv: No such file or directory
  
 
# ln -sf python2 python
 
# ln -sf python2 python
 +
# ln -sf virtualenv2 virtualenv
 
}}
 
}}
  
==Installing Mozilla Sync Server==
+
===Setup===
Setup process creates an isolated Python environment in which all necessary dependencies are downloaded and installed. This is why swapping Python versions is only needed during installation. Afterwards, running the server only relies on the isolated Python environment, independently of the system-wide Python.
+
Installation instructions:
 
+
Installation instructions (adapted from [http://docs.services.mozilla.com/howtos/run-sync.html Mozilla Howto], Copyright 2010 Mozilla Foundation, CC BY-SA 2.5):
+
 
{{bc|
 
{{bc|
 
# mkdir -p /opt/weave
 
# mkdir -p /opt/weave
Line 69: Line 71:
 
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.
 
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.
  
==Restoring initial Python state==
+
===Python initial state restoration===
 +
Once the build is finished, restore the links in {{ic|/usr/bin}} to their original state.
 
{{bc|
 
{{bc|
 
# cd /usr/bin
 
# cd /usr/bin
 
# ln -sf python3 python
 
# ln -sf python3 python
 +
# rm -f virtualenv
 
}}
 
}}
  
==Configuration files==
+
==Configuration==
There are at least two configuration files we need to modify: {{ic|development.ini}} and {{ic|etc/sync.conf}}.
+
===Server-side configuration files===
If the Sync Server is backed by an Apache HTTP server, a third file must be adapted: {{ic|sync.wsgi}}. This section demonstrates how to do it.
+
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
  
==First Test Run==
+
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}}.
 +
 
 +
In {{ic|development.ini}}, locate the line:
 +
{{bc|1=
 +
args = ('/tmp/sync-error.log',)
 +
}}
 +
and change it to:
 +
{{bc|1=
 +
args = ('/var/log/weave/sync-error.log',)
 +
}}
 +
 
 +
In {{ic|etc/sync.conf}}, locate the line:
 +
{{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:
 +
{{bc|1=
 +
quota_size = 25600
 +
}}
 +
The fallback node URL must reflect the server's hostname (here {{ic|server-name.domain-name}}).
 +
Change:
 +
{{bc|1=
 +
fallback_node = <nowiki>http://localhost:5000/</nowiki>
 +
}}
 +
to:
 +
{{bc|1=
 +
fallback_node = <nowiki>http://server-name.domain-name:5000/</nowiki>
 +
}}
 +
 
 +
===Unprivileged User===
 +
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===
 +
In order to make the Sync Server start automatically at boot-time, create a startup script:
 +
{{hc|
 +
/etc/rc.d/mozillaweave|<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
 +
}}
  
==Automatic Startup of the Server==
+
===Client-side configuration===
 +
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>}}
  
==Client-side Configuration==
+
The "Advanced Settings" button allows fine tuning of the synchronized elements list, and the definition of the client hostname.
 +
==See also==
 +
* [http://docs.services.mozilla.com/howtos/run-sync.html Mozilla Sync Server Howto]
 +
* [http://alien.slackbook.org/blog/setting-up-your-own-mozilla-sync-server/ Great tutorial, by Eric Hameleers]
 +
* [[Owncloud]] has mozilla sync server application

Revision as of 16:02, 29 March 2013

This page is about special operations required in order to install Mozilla Sync Server.

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 article describes how to install it manually. Note that there is also an AUR package for it: mozilla-firefox-sync-server-hgAUR

Prerequisites

Dependencies

Before proceeding, you need to install python2, python2-virtualenv, sqlite, mercurial and 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:

$ su -
Password: 
# 

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, /usr/bin/python is a symbolic link to /usr/bin/python3 whereas Python 2 is /usr/bin/python2.

Before running setup, we must check the link and change it if necessary:

# cd /usr/bin
# ls -l python

    lrwxrwxrwx 1 root root 7  5 sept. 07:04 python -> python3

# ls -l virtualenv

    ls: cannot access virtualenv: No such file or directory

# ln -sf python2 python
# ln -sf virtualenv2 virtualenv

Setup

Installation instructions:

# mkdir -p /opt/weave
# cd /opt/weave
# hg clone https://hg.mozilla.org/services/server-full

      ... source repository cloning messages ...

# cd server-full
# make build

      ... many build messages, including harmless warnings ...

      ... end of the successful build messages:

Building the app 
  Checking the environ   [ok]
  Updating the repo   [ok]
  Building Services dependencies 
    Getting server-core     [ok]
    Getting server-reg     [ok]
    Getting server-storage     [ok]  [ok]
  Building External dependencies   [ok]
  Now building the app itself   [ok]
[done]

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.

Python initial state restoration

Once the build is finished, restore the links in /usr/bin to their original state.

# cd /usr/bin
# ln -sf python3 python
# rm -f virtualenv

Configuration

Server-side configuration files

Configuration files are used to define where databases and logs will be created. We will place databases in /opt/weave/data and log files in /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 /opt/weave/server-full in order to reflect these choices: development.ini and etc/sync.conf.

In development.ini, locate the line:

args = ('/tmp/sync-error.log',)

and change it to:

args = ('/var/log/weave/sync-error.log',)

In etc/sync.conf, locate the line:

sqluri = sqlite:////tmp/test.db

and change it to:

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:

quota_size = 25600

The fallback node URL must reflect the server's hostname (here server-name.domain-name). Change:

fallback_node = http://localhost:5000/

to:

fallback_node = http://server-name.domain-name:5000/

Unprivileged User

It is a good practice to run daemons as an unprivileged user. Create the group weave and the user sync for that purpose:

 # 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 /opt/weave and /var/log/weave

# chown -R sync:weave /opt/weave/*
# chown -R sync:weave /var/log/weave

Automatic Startup of the Server

In order to make the Sync Server start automatically at boot-time, create a startup script:

/etc/rc.d/mozillaweave
#!/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

The script must have execution rights:

# chmod 755 /etc/rc.d/mozillaweave

Start the Sync Server at boot by including mozillaweave in the Daemon list. It depends on the network so it should be placed accordingly.

For systemd:

/etc/systemd/system/mozillaweave.service
[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

Test start the server using:

# systemctl start mozillaweave
# systemctl status mozillaweave

Set the Sync Server to start at boot with:

# systemctl enable mozillaweave

Client-side configuration

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: http://server-name.domain-name:5000/

The "Advanced Settings" button allows fine tuning of the synchronized elements list, and the definition of the client hostname.

See also