The new Firefox synchronizer

Lead Image © Jorgen McLeman, 123RF.com

Give and Take

The Firefox Sync Server from Mozilla lets users keep bookmarks, open tabs, and saved passwords synchronized across several browsers. It is fairly straightforward to use the sync server with the Rasp Pi.

Shortly after we wrote about the Raspberry Pi Sync Server in issue 6 [1] of this magazine published in 2014, Mozilla changed the entire architecture for its synchronizer in favor of significantly better operability on the client side. In this article, I discuss how to install the transformed Mozilla server on the Raspberry Pi and how to coax Firefox, including the mobile version, into a working relationship with the nano-computer.

Previously, Firefox had no built-in synchronization for bookmarks. At some point, add-ons were introduced to retrofit this feature. In many of these add-on solutions, the links ended up in the cloud, whereas in other solutions, file servers were utilized as storage locations.

Add-on-based solutions became superfluous when the sync feature was implemented in Firefox. The configuration became a part of the standard settings, and the data was sent in encrypted form to a Mozilla server. At the server end, this was a lean solution; at the user end, however, it was more complicated.

Firefox encrypted all data to be synchronized locally with a key that never left the computer. The user was responsible for the key, and although the process of admitting new computers into the common pool was not difficult, it was tedious. Additionally, Mozilla was working on its Firefox operating system, thus making it entirely foreseeable that more services and not just synchronization would become available.

New Architecture

Mozilla took all of these requirements into consideration and then turned the architecture inside out. Now the user just has to log in to one central login server to gain access to all of the Mozilla services. For desktop users with Firefox 29 and later, this new sync service is called Sync-1.5.

Even though the old sync server (Sync 1.1) still runs on Mozilla, connecting to it is difficult for users running a current version of Firefox. Naturally, this affects servers set up by users on a Rasp Pi. Mozilla intends to withdraw support for the browser completely in the not too distant future. This means that the day is approaching when everyone will have to switch over to the new sync server.

Fortunately, switching to the current version is fairly simple, as discussed in the following paragraphs. In contrast to the slim PHP server [3], the new server is based on Python. The PHP server was essentially a replica that supported the sync protocol but otherwise had nothing to do with Mozilla. The new server, on the other hand, comes out of the Mozilla project where it will be continuously developed and maintained.

Installation

This project uses a relatively recent, standard Raspbian image. I used version 24.12.2014 for purposes of testing. This version contains way too many software packages for a server, but the available space should nonetheless be adequate because cookies, bookmarks, and so on don't take up much room. When setting up the computer for the first time, you should assign a name that is easy to remember and a permanent IP address. You need to enter the name you have chosen and the IP address into the /etc/hosts file of each client so that it is possible to access the server with all of the browsers. This file is located in the %systemroot%\system32\drivers\etc\hosts directory in Windows, both in the 32-bit and 64-bit versions.

To compile the sync server, you need a series of additional packages, which can be installed with the following commands:

sudo apt-get update
sudo apt-get install python-dev git-core python-virtualenv

These packages occupy some 60MB of additional storage space on the SD card. You should install the actual software using git. The server will be running under your own user account; therefore, you should first create the user and log in to the new account:

sudo adduser ffsync

After logging in as user ffsync, you should execute the following commands:

git clone https://github.com/mozilla-services/syncserver
cd syncserver
time make build

You need to download and compile all the necessary software packages from the Internet yourself. The entire process takes about 10 minutes.

The syncserver.ini file is found in the syncserver/ directory created with the git command. You will be modifying several settings in this file, in particular the one for public_url, by which you access the server, as well as the secret (see Listing 2). You should create the secret by calling

head -c 20 /dev/urandom | sha1sum

and inserting it at the appropriate place in the configuration file.

Next, start the server using:

local/bin/pserve syncserver.ini

Listing 2

Modifying Settings

01 [server:main]
02 use = egg:Paste#http
03 host = 0.0.0.0
04 port = 5000
05
06 [app:main]
07 use = egg:syncserver
08
09 [syncserver]
10 public_url = http://pi.myprivatenet.de:5000/
11 sqluri = sqlite:////home/ffsync/syncserver.db
12 secret = d2d98e5ef1fef469b21ba8de08a9e940e171a075

As a rule, the server issues several status messages (Figure 1) that indicate that the installation and first bootup have finished successfully. You should perform a clean integration of the server in the Init system as explained in the "Automatic Start" box. After that, the server will load automatically each time the system starts.

Figure 1: A status message appears with the process ID and the IP address when the sync server starts successfully.

Automatic Start

Linux makes the so-called "init system" available for starting programs during the system start and closing them during shutdown. A script containing special conventions is found in the /etc/init.d directory. The insserv program then automatically accomplishes the correct integration into the init system.

You should first copy the ffsync script (Listing 1 and online [2]) as root to the /etc/init.d/ directory. When doing this, you need to pay attention to the correct execution rights. Then, call up the command

sudo insserv ffsync

Now there should be two new symbolic links in the /etc/rc2.d directory that refer to the ffsync script. One of the links begins with Sxx, which the system calls during the start process. The other link begins with Kxx and is responsible for shutting down the sync server. A manual start and stop can also be performed with the command:

sudo /etc/init.d/ffsync start

In addition to the start option, restart and status options are also available.

Listing 1

ffsync

01 #! /bin/sh
02 ### BEGIN INIT INFO
03 # Provides:          ffsync
04 # Required-Start:    $remote_fs $syslog
05 # Required-Stop:     $remote_fs $syslog
06 # Default-Start:     2 3 4 5
07 # Default-Stop:      0 1 6
08 # Short-Description: Start Firefox SyncServer 1.5
09 # Description:       Start/Stop file of Firefox SyncServer (new version 1.5)
10 ### END INIT INFO
11
12 # Author: Bernhard Bablok <mail@bablokb.de>
13 #
14
15 # PATH should only include /usr/* if it runs after the mountnfs.sh script
16 PATH=/sbin:/usr/sbin:/bin:/usr/bin
17 DESC="Firefox SyncServer (1.5)"
18 NAME="ffsync"
19 DAEMON="/home/$NAME/syncserver/local/bin/pserve"
20
21 CONFIG_FILE="/home/$NAME/syncserver/syncserver.ini"
22 LOG_FILE="/var/log/$NAME/$NAME.log"
23 PID_FILE="/var/run/$NAME/$NAME.pid"
24 SCRIPTNAME="/etc/init.d/$NAME"
25
26 # Exit if the package is not installed
27 [ -x "$DAEMON" ] || exit 0
28
29  # Read configuration variable file if it is present
30 [ -r /etc/default/$NAME ] && . /etc/default/$NAME
31
32 # Load the VERBOSE setting and other rcS variables
33 . /lib/init/vars.sh
34
35 # Define LSB log_* functions.
36 # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
37 # and status_of_proc is working.
38 . /lib/lsb/init-functions
39
40 #
41 # execute the given action
42 #
43 do_action() {
44    if ! test -d "/var/run/$NAME"; then
45      mkdir "/var/run/$NAME"
46      chown $NAME:$NAME "/var/run/$NAME"
47    fi
48    if ! test -d "/var/log/$NAME"; then
49      mkdir "/var/log/$NAME"
50      chown $NAME:$NAME "/var/log/$NAME"
51    fi
52    "$DAEMON" --log-file="$LOG_FILE" --pid-file="$PID_FILE" \
                --user="$NAME" --group="$NAME" "$CONFIG_FILE" "$1"
53 }
54
55
56 case "$1" in
57  start)
58    [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
59    do_action "start"
60    case "$?" in
61       0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
62       2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
63    esac
64    ;;
65   stop)
66    [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
67    do_action "stop"
68    case "$?" in
69       0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
70       2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
71    esac
72    ;;
73   status)
74    [ "$VERBOSE" != no ] && log_daemon_msg "Querying status of $DESC" "$NAME"
75    do_action "status"
76    ;;
77   restart|force-reload)
78   [ "$VERBOSE" != no ] && log_daemon_msg "Restarting $DESC" "$NAME"
79    do_action "restart"
80    case "$?" in
81       0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
82       2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
83    esac
84    ;;
85   *)
86   echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
87    exit 3
88    ;;
89 esac
90
91 :

Buy this article as PDF

Express-Checkout as PDF

Pages: 6

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content