Banana Pi / Arch Linux / Seafile

When experiencing some weird issues with OwnCloud (synchronization and performance problems), I decided to try an alternative.

After some research, I found seafile which got my attention.

Setup up the seafile server

Unfortunately, I only found pre-built packages for x86, x64 and Raspberry Pi. I tried to build the seafile server on the BPi, but that didn’t really work out, as there are a lot of deprecated dependencies and the like. I decided to use the Raspberry Pi version which seems to work perfectly.

We start by installing the required dependencies (don’t forget to add “armv7h” to arch array where required):

yaourt -S python-setuptools python2-setuptools python2-imaging mysql-python libselinux

Add a dedicated seafile user for security purposes, create a password for that user and logging into a shell with that user:

sudo -s
useradd -m -s /bin/false seafile
passwd seafile
exit
sudo -s -u seafile
cd $HOME

We download the current seafile server for the Raspberry Pi and extract the package:

wget https://bitbucket.org/haiwen/seafile/downloads/seafile-server_4.0.1_pi.tar.gz
tar -zxvf tar -xzvf seafile-server_4.0.1_pi.tar.gz
rm seafile-server_4.0.1_pi.tar.gz
cd seafile-server-4.0.1/
./setup-seafile-mysql.sh

The setup itself should be self-explanatory.

When finished, edit the SERVICE_URL variable in /home/seafile/ccnet/ccnet.conf to enable SSL for the next step:

SERVICE_URL = https://cloud.example.com:443/

Setup the web frontend

The next step is to make the web front end (called “seahub”) accessible.

Please refer to my blog post OwnCloud with nginx on how to install nginx and setup a self-signed certificate. I will just show you the virtual host configuration for nginx:

server {
    listen 443 ssl;
    server_name cloud.example.com;
    ssl_certificate /etc/ssl/server.crt;
    ssl_certificate_key /etc/ssl/server.key;

    error_page 497  https://$host:$server_port$request_uri;

    client_max_body_size 10G; # set max upload size

    location / {
        fastcgi_pass    127.0.0.1:8000;
        fastcgi_param   SCRIPT_FILENAME     $document_root$fastcgi_script_name;
        fastcgi_param   PATH_INFO           $fastcgi_script_name;

        fastcgi_param   SERVER_PROTOCOL $server_protocol;
        fastcgi_param   QUERY_STRING        $query_string;
        fastcgi_param   REQUEST_METHOD      $request_method;
        fastcgi_param   CONTENT_TYPE        $content_type;
        fastcgi_param   CONTENT_LENGTH      $content_length;
        fastcgi_param   SERVER_ADDR         $server_addr;
        fastcgi_param   SERVER_PORT         $server_port;
        fastcgi_param   SERVER_NAME         $server_name;
        fastcgi_param   HTTPS   on;
        fastcgi_param HTTP_SCHEME https;

        access_log      /var/log/nginx/seahub.access.log;
        error_log       /var/log/nginx/seahub.error.log;
    }
    location /seafhttp {
        rewrite ^/seafhttp(.*)$ $1 break;
        proxy_pass http://127.0.0.1:8082;
        client_max_body_size 0;
    }
}

When nginx is restarted, you are ready to test the seafile and seahub application by the previous created seafile user:

./seafile.sh start
./seahub.sh start-fastcgi

Of course we want a nicely systemd unit. So abort the previous mentioned applications.
Create a new file /usr/lib/systemd/system/seafile.service with root privileges and add the following content:

[Unit]
Description=seafile
After=network.target mysqld.service

[Service]
Type=oneshot
RemainAfterExit=yes 
User=seafile
ExecStart=/home/seafile/seafile-server-latest/seafile.sh start
ExecStart=/home/seafile/seafile-server-latest/seahub.sh start-fastcgi
ExecStop=/home/seafile/seafile-server-latest/seafile.sh stop
ExecStop=/home/seafile/seafile-server-latest/seahub.sh stop

[Install]
WantedBy=multi-user.target

Finally reload the daemons and start your seafile service via systemd:

systemctl daemon-reload
systemctl enable seafile
systemctl start seafile

Ports

To connect to your seafile server from the internet, you have to forward three ports to your device (see Firewall settings):

  • 443: HTTPS
  • 10001: Ccnet daemon
  • 12001: Seafile daemon

WebDAV

Optionally you might enable WebDAV functionality to connect to your seafile server via Windows explorer or Android apps that are not supporting the native seafile protocol.

First edit /home/seafile/conf/seafdav.conf:

[WEBDAV]
enabled = true
port = 8080
fastcgi = true
share_name = /seafdav

Second add the following location configuration within your server section in /etc/nginx/nginx.conf:

location /seafdav {
    fastcgi_pass    127.0.0.1:8080;
    fastcgi_param   SCRIPT_FILENAME
    $document_root$fastcgi_script_name;
    fastcgi_param   PATH_INFO           $fastcgi_script_name;

    fastcgi_param   SERVER_PROTOCOL     $server_protocol;
    fastcgi_param   QUERY_STRING        $query_string;
    fastcgi_param   REQUEST_METHOD      $request_method;
    fastcgi_param   CONTENT_TYPE        $content_type;
    fastcgi_param   CONTENT_LENGTH      $content_length;
    fastcgi_param   SERVER_ADDR         $server_addr;
    fastcgi_param   SERVER_PORT         $server_port;
    fastcgi_param   SERVER_NAME         $server_name;

    fastcgi_param   HTTPS               on;
    fastcgi_param   HTTP_SCHEME         https;

    client_max_body_size 0;

    access_log      /var/log/nginx/seafdav.access.log;
    error_log       /var/log/nginx/seafdav.error.log;
}

Now restart your seafile and nginx servers again and you should have WebDAV access via https://cloud.example.com/seafdav.

Upgrade from 3.1.6

In previous versions of this blog post, I used the version 3.1.6. To upgrade, also download the newer version, make a backup of your database and run the upgrade script:

sudo systemctl stop seafile
sudo -s -u seafile
cd $HOME
mysqldump -u seafile -p seafile-db > seafile_database_backup.sql
# download and unpack version 4.0.1
cd seafile-server-4.0.1/upgrade
./upgrade_3.1_4.0.sh
exit
sudo systemctl start seafile

Conclusion

And that’s it!
I had a much better overall experience. The performance was noticeably better using the Linux client and the web frontend compared to OC. Moreover I couldn’t find synchronization problems right now. I’m curious, how seafile performances in the next days.

References

7 comments:

    1. Hello Mattia,
      It should work similar. Keep in mind, that in Debian based environments, you usually use apt to install packages. Also I’m not sure, how the required packages are named on Debian. After configuring Nginx and MySQL the rest should be the same.

  1. Hi Ryad.

    I have an issue with pacman -S libselinux .
    This package is not part of the “out of the box” repos.

    So I get the following error during the installation process:

    ccnet-init: error while loading shared libraries: libselinux.so.1: cannot open shared object file: No such file or directory

    All my investigations did not show any solution. And it seems to me, that I am not the only one with this problem. (see http://archlinuxarm.org/forum/viewtopic.php?f=59&t=6673 )

    It would be great, if you could give me a hint.

    Kind regards
    Tilmann

    1. Hello Tilmann,
      As you mentioned, libselinux is not in the official repositories. Therefore you need to compile it for yourself from the AUR.

      You can build the libselinux for yourself by downloading the tarball from the AUR , unpacking it and run “makepkg” within the new folder. You will need to add “armv7h” in the arch array from the PKGFILE previously. After the building process you’ll get a file libselinux-2.3-3-armv7h.pkg.tar.xz which you can install with pacman (pacman -U libselinux-2.3-3-armv7h.pkg.tar.xz).

      I did the building for you, so you can just do the pacman -U command: http://blog.eldajani.net/libselinux-2.3-3-armv7h.pkg.tar.xz
      Still I recommend learning to build from AUR.

      By the way: The whole previous mentioned process can be semi-automated by an AUR wrapper application. I recommend yaourt as it’s simple and straight forward. This way you just have to type yaourt -S libselinux to prepare, build and install the AUR package.

    1. Hi nferenc,

      thanks for your feedback. I forgot to mention, that besides the standard HTTPS port you need to forward two other ports. I updated this article and also added a chapter for WebDAV configuration.

      Regards,
      Ryad

Leave a Reply

Your email address will not be published. Required fields are marked *