Warung.☕

The real seafile setup guide

2021/06/14

This guide is for those who wants to deploy Seafile on an LXC container instead of docker.

Launching a container

Please use Fedora/33 image from the official lxc remote, as It's the only distro with an official seafile support for the latest version.

# lxc launch images:fedora/33 seafile

Required depedency

We're going to use SQlite for simpler database.

# yum install sqlite python-ldap python-setuptools python-memcached python-requests python-urllib3
# pip3 install --ignore-installed django-simple-captcha

Initial setup

Manually download the latest version of the server package from their download page under the "Server for generic Linux" section.

Then Follow directory layout setup here.

Setup

# cd seafile-server-*
# ./seafile.sh start
# ./seahub.sh start # some initial setups

Additional setup ( for non-root domain )

Instead of writing port number to access the web client, we'll use reverse proxy and url path instead. I'm going to use /cloud/ as the url path and HAProxy for the reverse proxy since it has a balance of config readability, usability, and feature-rich enough for self-hosted server.

Go to the conf directory

# cd ../conf/

Edit ccnet.conf ( for sharing links )

[General]
SERVICE_URL = http://<container-ip>/cloud/

Edit seafile.conf ( to enable public ip )

host=0.0.0.0

Edit gunicorn.conf.py ( for, idk, webserver? )

bind = "0.0.0.0:8000"

Edit seahub_settings.py ( for seahub web client )

SERVE_STATIC = True -> force enable static handlers
MEDIA_URL = '/cloud/media/'
COMPRESS_URL = MEDIA_URL
STATIC_URL = MEDIA_URL + 'assets/'
SITE_ROOT = '/cloud/'
LOGIN_URL = '/cloud/accounts/login/'
LOGOUT_URL = '/cloud/accounts/logout/'
FILE_SERVER_ROOT = '/seafhttp'

HAProxy config

frontend proxy
        bind *:80
        
        acl cloud-media path_beg -i /cloud/media
        use_backend sfm-be if cloud-media

        acl sfhttp path_beg /seafhttp
        use_backend sfhttp-be if sfhttp

        acl cloud path_beg -i /cloud
        use_backend sf-be if cloud !cloud-media

backend sfhttp-be
        http-request replace-path /seafhttp/(.*) /\1
        server seafile-server <container-ip>:8082

backend sfm-be
        http-request replace-path /cloud/media/(.*) /cloud/cloud/media/\1
        server code-server <container-ip>:8000

backend sf-be
        server code-server <container-ip>:8000

No, I did not make a typo in the replace-path. I have to write /cloud/cloud/ on the backend setup not because of HAProxy, but because of seahub server somehow decided to give users a decision to handle the static files themeselves using their own reverse proxy.

No one knows who and why they decided to use different root for media in the first place. Took me a couple of hours to realise that It's all seahub's fault after all.

Run as a service

Create a file /etc/sysconfig/seafile

# Change the value of "user" to your linux user name
user=root

# Change the value of "seafile_dir" to your path of seafile installation
# usually the home directory of $user

seafile_dir=<seafile dir here>
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

Then continue creating init for seafile and seahub service by copying the script provided by seafile here then register the service as usual.

(Optional) Seafile-cli

You can install an optional seafile cli if you want. But most people use rclone for offline media sync instead.

Create /etc/yum.repos.d/seafile.repo

[seafile]
name=seafile
baseurl=https://linux-clients.seafile.com/seafile-rpm/fedora33
gpgcheck=0
enabled=1
# yum install seafile-daemon

Notes about seafile-cli:


Resources