This commit is contained in:
shim_ 2018-09-09 17:12:01 +02:00
commit 58a2231e35
7 changed files with 300 additions and 0 deletions

6
.drone.yml Normal file
View File

@ -0,0 +1,6 @@
pipeline:
docker:
image: plugins/docker
repo: repo.shimun.net/shimun/seafile
registry: repo.shimun.net
secrets: ["docker_username", "docker_password"]

24
Dockerfile Normal file
View File

@ -0,0 +1,24 @@
FROM frolvlad/alpine-glibc
ENV SEAF=/opt/seafile
RUN apk add --no-cache py-pip sqlite-dev py-mysqldb py-pillow curl bash openssl-dev libevent
COPY requirements.txt /tmp/requirements.txt
RUN pip install -r /tmp/requirements.txt
COPY conf $SEAF/
COPY scripts/upgrade.py /usr/local/sbin/upgrade
COPY scripts/seafile-server.sh /sbin/seafile-server
RUN ulimit -n 30000 && mkdir -p $SEAF/pids && rm /tmp/requirements.txt && \
chmod +x /usr/local/sbin/upgrade /sbin/seafile-server
VOLUME /opt/seafile
EXPOSE 80 10001 12001 8000 8080 8082
# Baseimage init process
ENTRYPOINT ["/sbin/seafile-server"]
#Default to run options include: run, run-upgrade, upgrade, stop, stop-upgrade
CMD ["run-upgrade"]

6
conf/seafdav.conf Normal file
View File

@ -0,0 +1,6 @@
[WEBDAV]
enabled = true
port = 8080
fastcgi = true
host = 0.0.0.0
share_name = /seafdav

77
nginx.conf Normal file
View File

@ -0,0 +1,77 @@
events {
worker_connections 12;
}
pid /opt/seafile/pids/nginx.pid;
server {
listen 80;
error_log syslog:server=unix:/dev/log;
access_log syslog:server=unix:/dev/log;
upstream hub {
server 127.0.0.1:8000;
keepalive 2;
}
upstream files {
server 127.0.0.1:8082;
keepalive 4;
}
upstream webdav {
server 127.0.0.1:8080;
keepalive 2;
}
proxy_set_header X-Forwarded-For $remote_addr;
location / {
proxy_pass http://hub;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_read_timeout 1200s;
# used for view/edit office file via Office Online Server
client_max_body_size 0;
}
location /seafhttp {
rewrite ^/seafhttp(.*)$ $1 break;
proxy_http_version 1.1;
proxy_pass http://files;
client_max_body_size 0;
proxy_connect_timeout 3s;
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
send_timeout 3600s;
}
location /seafdav {
fastcgi_pass webdav;
fastcgi_keep_conn on;
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;
client_max_body_size 0;
}
location /media {
root /opt/seafile/seafile-server-latest/seahub/media/
}
}

6
requirements.txt Normal file
View File

@ -0,0 +1,6 @@
requests
scriptine
setuptools
simplejson
python-memcached
urllib3

82
scripts/seafile-server.sh Executable file
View File

@ -0,0 +1,82 @@
#!/bin/sh
LATEST=$SEAF/seafile-server-latest
PIDS=$SEAF/pids
function stop() {
$0 stop
}
case "$1" in
run)
if [ ! -e "$LATEST" ]; then
(>&2 echo This appears to be the fist run, installing..)
$0 run-upgrade
else
$0 manage-component seaf-server start $LATEST/seafile.sh start
$0 manage-component seahub start $LATEST/seahub.sh "${SEAF_HUB_MODE:-start} 8000" &
$0 manage-component nginx start nginx &
wait
fi
trap stop SIGINT SIGTERM
while pgrep -f "seafile-controller" 2>&1 >/dev/null; do
sleep 2;
done
;;
run-upgrade)
$0 upgrade && $0 run
;;
stop)
$0 manage-component seaf-server stop &
$0 manage-component seahub stop &
$0 manage-component nginx stop &
$0 manage-component ccnet stop &
wait
;;
stop-upgrade)
$0 stop && $0 upgrade
;;
upgrade)
/usr/local/sbin/upgrade main
kill -SIGHUP $(pgrep -o nginx) #Reload nginx
;;
manage-component)
mkdir -p /var/run/seafile
NAME="$2"
PIDFILE=/var/run/seafile/$NAME.pid
case "$3" in
start)
CMD="$4"; ARGS="$5"
"$CMD $ARGS &"
sleep 1
( ! "$0 $1 $NAME status") && ((>&2 echo Failed to start $NAME); exit 1)
PID=$?
#echo $PID > /var/run/seafile/$NAME.pid
;;
status)
([ -e "$PIDFILE" ] && kill -0 $(cat $PIDFILE) 2> /dev/null && echo Running) || (echo Stopped && exit 1)
;;
stop)
if "$0 $1 $NAME status"; then
kill $(cat $PIDFILE)
TRIES=30
while "$0 $1 $NAME status"; do
TRIES=$((TRIES - 1))
if [ $TRIES -eq 0 ]; then
(>&2 echo Failed to stop $NAME)
exit 1
fi
sleep 1
done
(>&2 echo $NAME has been stopped)
else
(>&2 echo $NAME is not running)
exit 1
fi
;;
esac
;;
*)
(>&2 echo Unknown option $1 options include: run, run-upgrade, upgrade, stop, stop-upgrade)
;;
esac

99
scripts/upgrade.py Executable file
View File

@ -0,0 +1,99 @@
#! /usr/bin/env python
import requests, platform, re, collections, tempfile, os, sys, shutil
from subprocess import call
version_re = "seafile-server-?_?([\d\.]*)"
seaf_home = os.environ["SEAF"] or "/opt/seafile"
def available(page):
(arch, _) = platform.architecture()
if arch == "64bit":
arch = "x86-64"
else: arch = "i386"
link = "http(s?):\/\/[^ \"\(\)\<\>]*%s_?%s.tar.gz" % (version_re ,arch)
resp = requests.get(page)
available = {}
for m in re.finditer(link, resp.text):
available[m.group(2)] = m.group(0) #{version: link}
return collections.OrderedDict(sorted(available.items(), reverse=True))
def list_command(page="https://www.seafile.com/en/download/"):
for (version, link) in available(page).items():
print("- %s: %s" % (version, link))
return 0
def current_version_command():
print(current_version())
def current_version():
current = os.path.realpath(os.path.join(seaf_home, "seafile-server-latest"))
res = re.findall(version_re,current)
res[0] = "0" + res[0]
return '.'.join(res)
def perform_upgrade_command(version,mysql=False,yes=True):
scripts = os.path.join(seaf_home,"seafile-server-%s" % version, "upgrade")
current = map(lambda x: int(x), current_version().split("."))
target = map(lambda x: int(x), version.split("."))
print len(current) == 1 and current[0] == 0
if len(current) == 1 and current[0] == 0: #Not installed
installer = os.path.join(seaf_home,"seafile-server-%s" % version,"setup-seafile%s.sh" % ("-mysql" if mysql else ""))
call(["sh","-c",installer],stdout=sys.stdout, stdin=sys.stdin)
return 0
script_re = "^upgrade_(\d+).(\d+)_(\d+).(\d+)\.sh$"
run = []
last = None
for s in os.listdir(scripts):
m = re.match(script_re, s)
if m:
comp = map(lambda x: int(x), m.groups())
last = (s, comp)
(major, minor, minorsub, rev) = comp
if current[0] <= major and minor > current[1]:
run.append(s)
for script in run:
cmd = []
if yes: cmd.append("echo -ne '\n'")
cmd.append(script)
call(["/bin/sh", "-c", ''.join(cmd)], stdout=sys.stdout, stdin=(None if yes else sys.stdin))
def install_command(url):
tmp = tempfile.mkdtemp()
if call(["/bin/sh", "-c", 'cd %s; curl %s | tar xzv' % (tmp, url)]) == 0:
for f in os.listdir(tmp):
if len(re.findall(version_re, f)) > 0:
dest = os.path.join(seaf_home, os.path.basename(f))
shutil.move(os.path.join(tmp,f), dest)
current = current_version()
target_version = ''.join(re.findall(version_re,dest))
if len(current) == 1: current = current[0]
else: current = "0.0.0"
print("Upgrading from: %s -> %s" % (current, target_version))
perform_upgrade_command(target_version)
if len(os.listdir(tmp)) != 0:
print("Failed to unpack update")
os.rmdir(tmp)
return 1
os.rmdir(tmp)
return 0
def main_command(version="latest",page="https://www.seafile.com/en/download/"):
avail = available(page)
install = None
if version == "latest":
install = avail.items()[0]
else:
if version in dict(avail.items()):
install = dict(avail.items())[version]
if install:
print("Installing: %s" % install[1])
return install_command(install[1])
else:
print("Couldn't determine download for %s" % version)
return 1
if __name__ == '__main__':
import scriptine
scriptine.run()