Archives

All posts for the month June, 2020

Recently I decided to use Ubuntu 20.04 on my new Raspberry Pi 4B, and use Seafile on an external hard drive. This is how I got it working, and some troubleshooting tips I found. The server install instructions are somewhat outdated (particularly things like the prerequisites – it targets Ubuntu 14.04, and is still working with Python 2 when the latest Seafile uses Python 3). It’s worth glancing through anyway, just don’t take it as gospel.

First, it’s important to use the 32 bit version of Ubuntu otherwise you’ll get very weird “Not Found” errors for files that are actually there – this happens when you’re running on the wrong architecture. To fix this you’d have to recompile the whole thing, which I’ve tried and had major problems with before on a Synology NAS. That was a couple of years ago though, and Synology is a pain in the first place, so maybe you’d have better luck.

If you’re putting things on an external drive, Seafile say to use MySQL instead of Sqlite – presumably going by their backup instructions that tell you to backup the DB first this is to make sure things don’t go corrupt if it unexpectedly disconnects. So install the MySQL server (I’m using MariaDB here, but either should work):

sudo apt install mariadb-server

Choose where you want to store things. Note everything is stored under this directory – other directories will be created under it by the setup script. While it seems like you can move it around afterwards, the setup script hardcodes a couple of things that stop it working and don’t give good error messages, so don’t. I have my external HD mounted at /ext, so:

mkdir /ext/seafile
cd /ext/seafile

Download and extract the latest version (7.1.4 as I’m writing this) – the Buster version is Debian 10, which I believe is closest to Ubuntu 20.04:

wget https://github.com/haiwen/seafile-rpi/releases/download/v7.1.4/seafile-server_7.1.4_pi-buster-stable.tar.gz
tar -zxf seafile-server_7.1.4_pi-buster-stable.tar.gz
mkdir installed
mv *.gz installed/
cd seafile-server-7.1.4

Don’t bother renaming the resulting folder to remove the version – a symlink to the latest one is automatically created in the setup script.

The 7.1.4 package has a bug in where it stores certain Python packages – to fix it create a symlink. Note this is just where Seafile is internally storing packages, it doesn’t require that specific Python version – 20.04 uses 3.8 and that’s fine:

ln -s python3.7 seafile/lib/python3.6

You now need to run the setup script – since I’m using MySQL I’m using that version, otherwise use the other. Note MariaDB (and probably MySQL, but I’m not sure) have a weird thing where the MySQL root user can ONLY be accessed by the system root user. So use sudo here and chown the resulting files later. When it asks for the root password just type anything, like 123, unless you’ve specifically set it. For the mysql user password choose something secure obviously. It’ll ask for a admin email+password, this is what you’ll log into the server as.

sudo ./setup-seafile-mysql.sh
cd ..
sudo chown -R ubuntu * # ubuntu is default, obviously substitute if required
cd seafile-server-latest

Now while technically by the instructions you should be ready to start things, with the exact versions I’m using here seahub will fail to start. Annoyingly by default it doesn’t tell you, or even log, why. So if you’re using the exact versions I am, here’s how to fix things, otherwise scroll down for how to start and debugging instructions:

PIL and Pillow are a python image library compiled specifically for the system they’re used on, and apparently Debian Buster and Ubuntu 20.04 are using different versions which causes an error when starting the server. So to fix this:

sudo apt install python3-pil
cd seahub/thirdpart/
mkdir DISABLED
mv PIL DISABLED/
mv Pillow-7.1.2.dist-info/ DISABLED/
cd ../..
Similarly with the Crypto module (causes an empty response when trying to access the site):
sudo apt install python3-crypto
cd seahub/thirdpart/
mv Crypto DISABLED/
cd ../..

Now, to attempt to start the server:

./seafile.sh start
./seahub.sh start

If things go wrong, particularly when starting seahub as it doesn’t give error messages by default, you can try ./seahub.sh start-fastcgi – this won’t work, as Django has discontinued fastcgi support, but will actually give you error messages if the problem is before that point. Otherwise:

nano ../conf/seahub_settings.py

Add the line (watch the capitalisation): DEBUG = True

If you still aren’t getting useful error messages:

nano ../conf/gunicorn.conf.py

Change the line daemon=True to daemon=False – remember to change this back once you work out what’s wrong.

Now with luck Seafile is running locally, but you won’t be able to access the web interface from another computer unless you either change a config setting or install a reverse proxy. If you’re testing locally to check if it’s working, use wget instead of curl as the latter returns an empty response for some reason.

To access from your local network without a reverse proxy, replace 127.0.0.1 with your Pi’s IP in the following:

nano ../conf/gunicorn.conf.py
./seahub.sh restart

You can then access it by going to youripaddress:8000 – you can change the port in the above file but ports <1024 need either to be run as root or using a workaround – using a reverse proxy fixes this.

That’s pretty much it. When using the clients (Seafile Sync Client if you want stuff kept on your computer like Dropbox, Seafile Drive Client if you want stuff to stay on the server), and the iOS/Android clients, make sure to use the whole http://youripaddress:8000 URL for the server.

Running automatically on boot

First make sure the external HD is mounted automatically – add to /etc/fstab (substituting device, mountpoint and filesystem type obviously):

/dev/sda1 /ext ext4 defaults 0 0

Finally, to make seafile and seahub start on boot, follow the instructions here – I changed the user/group to be ubuntu, just for simplicity, but you could use a specific seafile user if you wanted.

Backups

If you want to set up backups, make sure to do the database first, then the files. I just backup the databases to a subfolder on /ext/seafile, and then backup that whole folder. To do so keeping backups for a month (after creating the directory):

sudo crontab -e

Add the line (making sure to get the quotes right, and escaping the %):

0 0 * * * sudo mysqldump --all-databases | gzip > /ext/seafile/mariadb-backups/mariadb_`date +"\%d"`.sql.gz

Then just set up the backup of the /ext/seafile directory (I’m backing up to a second, far older, raspberry pi – already set up with ssh-keygen and ssh-copy-id):

# Either using Duplicity:
10 0 * * * duplicity --no-encryption /ext/seafile sftp://pi@myotherraspberrypi/ext/seafile-backups
# OR using just rsync (good if using btrfs snapshots / snapper on target):
10 0 * * * rsync -az /ext/seafile pi@myotherraspberrypi:/ext/seafile-backups

If you have problems with Duplicity not recognising your RSA key, try the following to convert to a compatible format:

ssh-keygen -p -m PEM -f ~/.ssh/id_rsa