Building a File Server on a Raspberry Pi with Seafile

Stacy Prowell
The Startup
Published in
6 min readNov 30, 2019

--

I recently replaced the 1TB spinning drives in my kids’ desktops with SSD drives, which left me wondering what to do with the spinning drives. I had a little Raspberry Pi 3 sitting idle (replaced with a Pi4), an old USB hard drive dock (replaced with a USB 3 dock). I decided we could always use more shared file storage, and so I set up a little file server using Seafile and a few other things. This document describes getting it up and running with Seafile.

The Basics

The first step was setting up the hardware. I used (almost) entirely “spare parts” for this, but if you wanted to fully replicate what I did, the components are really cheap.

  • Raspberry Pi 3 (available lots of places; I see it for $35 on Adafruit)
  • Two 1TB Western Digital hard drives (that’s what I had, but spinning disks are cheap these days; I see a 1TB Western Digital drive for $39 on Newegg)
  • I used a USB 2 hard drive dock (a USB 3 dual SATA dock costs just $25 on Newegg)

The great thing about the Pi 3 and later is that it has Wifi built-in. I was able to locate mine near the router and plug it in there, so I didn’t need Wifi. But it’s there if you need it.

I said “almost” entirely spare parts. I wanted a UPS for our cable modem and router, so I bought one for $45. I also used that for the Pi and the dock. This allows the Pi to sync the file systems, unmount the drives, and shut down in the event power fails.

I also had a touchscreen Pi display and wireless keyboard from my old media center project, so I used those. But that’s a bit of overkill, I think. You can certainly run the Pi headless after you set up SSH.

  • SmartiPi touchscreen display (currently $20 on Adafruit)
  • Logitech K400 keyboard and touchpad (currently $40 on Newegg)

Total cost if I had to buy it all new today (fall of 2019): $204.

I installed Raspian on the Pi, plugged up all the hardware, and then set about configuring SSH so I could put it under a table somewhere and not worry about it.

Installing and Configuring Seafile

Seafile provides open source file syncing and sharing and works much like Dropbox. It provides for file syncing, but also provides a remote drive that can be mounted to access files without having to copy them over, and a wiki to share information.

My main source for setting up the Seafile server was the Seafile manual, but I also read through a prior writeup right here on Medium that used an older version of Seafile.

A really good source of information was the Seafile book available on GitBook.

1. Prerequisites

Some items need to be installed first. These instructions will assume you are logged in as the usual pi user and can escalate privilege using sudo (which is the default).

$ sudo pip install certifi idna
$ sudo apt install sqlite3

For my installation both certifi and idna were already installed.

2. Setting Up the Seafile Data Store

I used the second drive /data/b as the Seafile storage and created a group for it.

$ sudo addgroup seafile
$ sudo addgroup pi seafile
$ sudo mkdir /data/b/seafile
$ sudo chgrp seafile /data/b/seafile
$ sudo chmod g+rwxs /data/b/seafile

3. Download and Start Install

Download the latest version of Seafile. As I write this it is 7.0.5. Releases are available from https://github.com/haiwen/seafile-rpi/releases.

$ cd /data/b/seafile
$ mkdir installed
$ wget https://github.com/haiwen/seafile-rpi/releases/download/v7.0.5/seafile-server_7.0.5_stable_pi.tar.gz
$ tar xvf seafile-server_*
$ mv seafile-server_*.gz installed

The above instructions save the downloaded tarball in a new installed folder, which is not strictly necessary but is recommended in the manual.

After running these commands I had the following files and folders.

$ tree | head
.
├── installed
│ └── seafile-server_7.0.5_stable_pi.tar.gz
└── seafile-server-7.0.5
├── check_init_admin.py
├── reset-admin.sh
├── runtime
│ └── seahub.conf
├── seaf-fsck.sh
├── seaf-fuse.sh

4. Install

Run the install script.

$ cd seafile-server_*
$ ./setup-seafile.sh

The script will check the dependencies (that should have been handled in step one above). You then need to answer some questions.

  • Pick a name for the server. Mine is pine. No particular reason.
  • Specify the server’s IP address. My home network supports name resolution, so I just used the hostname of my Pi. If you use an IP address make it reserved on your DHCP server so that you get the same IP address every time.
  • I used /data/b/seafile created above to store my Seafile data.
  • I used the recommended port of 8082.

At the end of this, I had the following files and folders (a few omitted here by -L 2). Note the symbolic link to the folder containing the distribution.

$ tree -L 2
.
├── ccnet
│ ├── GroupMgr
│ ├── misc
│ ├── mykey.peer
│ ├── OrgMgr
│ ├── PeerMgr
│ └── seafile.ini
├── conf
│ ├── ccnet.conf
│ ├── gunicorn.conf
│ ├── seafdav.conf
│ ├── seafile.conf
│ └── seahub_settings.py
├── installed
│ └── seafile-server_7.0.5_stable_pi.tar.gz
├── seafile-data
│ ├── library-template
│ └── seafile.db
├── seafile-server-7.0.5
│ ├── check_init_admin.py
│ ├── reset-admin.sh
│ ├── runtime
│ ├── seaf-fsck.sh
│ ├── seaf-fuse.sh
│ ├── seaf-gc.sh
│ ├── seafile
│ ├── seafile.sh
│ ├── seahub
│ ├── seahub.sh
│ ├── setup-seafile-mysql.py
│ ├── setup-seafile-mysql.sh
│ ├── setup-seafile.sh
│ ├── sql
│ └── upgrade
├── seafile-server-latest -> seafile-server-7.0.5
├── seahub-data
│ └── avatars
└── seahub.db

5. After Install

Before you start the server, you should update the conf/gunicorn.conf file created during installation. See the note here. You’ll see the file in the tree listing at the end of the previous step. You need to find these lines:

# default localhost:8000
bind = "127.0.0.1:8000"

Change the bind line to have address 0.0.0.0.

# default localhost:8000
bind = "0.0.0.0:8000"

If you fail to make this change you will get “connection refused” when you try to connect remotely to the server.

Now we can start the Seafile server and verify that it works. We can also start the Seahub web interface.

$ cd seafile-server-latest
$ ./seafile.sh start
$ ./seahub.sh start

The first time you start the Seahub server it will ask some questions. I used my email address as the admin email, and I set an admin password. Remember this: it is how you will log in through the web interface to manage the server.

Next, you should connect to the Seahub server athttp://localhost:8000 (or the appropriate port if you changed it). You should really use a graphical browser to do this, and I did this from the Pi itself.

You should stop these in the opposite order that you start them.

$ ./seahub.sh stop
$ ./seafile.sh stop

I set up a script in /etc/init.d to automatically start everything when the machine boots, following the instructions for “For other Debian based Linux” in the GitBook chapter on starting Seafile at system bootup.

I created the file /etc/init.d/seafile-server with the following content.

#!/bin/sh### BEGIN INIT INFO
# Provides: seafile-server
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Starts Seafile Server
# Description: starts Seafile Server
### END INIT INFO
# Change the value of "user" to your linux user name
user=pi
# Change the value of "script_path" to your path of seafile installation
seafile_dir=/data/b/seafile
script_path=${seafile_dir}/seafile-server-latest
seafile_init_log=${seafile_dir}/logs/seafile.init.log
seahub_init_log=${seafile_dir}/logs/seahub.init.log
# Change the value of fastcgi to true if fastcgi is to be used
fastcgi=false
# Set the port of fastcgi, default is 8000. Change it if you need different.
fastcgi_port=8000
case "$1" in
start)
sudo -u ${user} ${script_path}/seafile.sh start >> ${seafile_init_log}
if [ $fastcgi = true ];
then
sudo -u ${user} ${script_path}/seahub.sh start-fastcgi ${fastcgi_port} >> ${seahub_init_log}
else
sudo -u ${user} ${script_path}/seahub.sh start >> ${seahub_init_log}
fi
;;
restart)
sudo -u ${user} ${script_path}/seafile.sh restart >> ${seafile_init_log}
if [ $fastcgi = true ];
then
sudo -u ${user} ${script_path}/seahub.sh restart-fastcgi ${fastcgi_port} >> ${seahub_init_log}
else
sudo -u ${user} ${script_path}/seahub.sh restart >> ${seahub_init_log}
fi
;;
stop)
sudo -u ${user} ${script_path}/seafile.sh $1 >> ${seafile_init_log}
sudo -u ${user} ${script_path}/seahub.sh $1 >> ${seahub_init_log}
;;
*)
echo "Usage: /etc/init.d/seafile {start|stop|restart}"
exit 1
;;
esac

Next, enable it as follows.

$ sudo chmod +x /etc/init.d/seafile-server
$ sudo update-rc.d seafile-server defaults

Reboot. The Seafile server should be started automatically. You should be able to start a client and log in.

Seafile success!
Seafile success!

--

--

Stacy Prowell
The Startup

Stacy was in the garage, taking something apart. “I can fix it,” he said. Maybe. He is probably be the one who broke it.