26 Commits

Author SHA1 Message Date
c513f2ab95 no_media version 2018-11-11 18:32:35 +01:00
fb956cb777 reorganised nginx.conf
Some checks are pending
continuous-integration/drone/push Build is failing
2018-11-11 17:24:27 +01:00
bee6bd3200 mkdir pkg dir 2018-11-10 17:22:10 +01:00
6fb12158b0 Merge branch 'master' into nginx-deb 2018-11-10 15:36:29 +01:00
69824d3497 Merge branch 'pull_prev' into nginx-deb 2018-11-10 15:33:39 +01:00
2d20c8447d disable base image pull 2018-11-10 15:29:52 +01:00
3e8cadf6b8 utilise --cache-from PR 2018-11-10 15:23:41 +01:00
38da3057a3 more worker connections 2018-11-04 17:39:34 +01:00
8dc75bc553 improved commands 2018-11-03 21:11:55 +01:00
f3fde90cdc cache from 2018-11-03 20:00:46 +01:00
e65a401819 pull previous build 2018-11-03 18:24:15 +01:00
6250c23295 check nginx.conf 2018-11-03 17:52:36 +01:00
4683c54f44 media fallback 2018-11-03 17:52:16 +01:00
56dfa71a62 error codes 2018-11-03 15:13:46 +01:00
1b919a5c10 serve static 2018-10-04 16:31:17 +02:00
dabefc5047 improved systemd 2018-10-04 16:31:05 +02:00
9a62f2bc5e handle existing install 2018-10-04 16:30:46 +02:00
e72eb4b31f resume setup if possible 2018-09-13 21:25:25 +02:00
2f4724d0ad caching 2018-09-13 18:46:36 +02:00
a9763dcd8d keep resuming setup 2018-09-09 23:59:09 +02:00
e96bd34bf5 handle non existent env 2018-09-09 23:46:08 +02:00
2710feb490 include all options [CI SKIP] 2018-09-09 23:41:01 +02:00
fabee3bf11 can't download a tuple 2018-09-09 23:31:18 +02:00
52757828e5 sample systemd service 2018-09-09 23:15:54 +02:00
0c1f4f6c33 added array indices 2018-09-09 23:15:35 +02:00
27ec24d567 Merged working scripts into master(alpine) 2018-09-09 22:51:47 +02:00
13 changed files with 199 additions and 104 deletions

View File

@ -1,6 +1,17 @@
pipeline: pipeline:
nginx-conf:
image: nginx:mainline
commands:
- cp -r nginx /etc/nginx
- nginx -t
docker: docker:
image: plugins/docker image: plugins/docker
repo: repo.shimun.net/shimun/seafile repo: repo.shimun.net/shimun/seafile
registry: repo.shimun.net tag: no_media
secrets: ["docker_username", "docker_password"] registry: repo.shimun.net
storage_path: /drone/.docker
secrets: ["docker_username", "docker_password"]
storage_path: /drone/.docker
cache_from: ["repo.shimun.net/shimun/seafile", "repo.shimun.net/shimun/seafile:nginx-deb", "repo.shimun.net/shimun/seafile:alpine"]
use_cache: true
pull_image: false

View File

@ -14,7 +14,7 @@ RUN apt update && apt install locales -y && apt install -y --no-install-recommen
COPY conf /opt/seafile/conf COPY conf /opt/seafile/conf
COPY conf /etc/seafile COPY conf /etc/seafile
COPY nginx.conf /etc/nginx/nginx.conf COPY nginx /etc/nginx
COPY scripts/upgrade.py /usr/local/sbin/upgrade COPY scripts/upgrade.py /usr/local/sbin/upgrade
COPY scripts/seafile-server.sh /sbin/seafile-server COPY scripts/seafile-server.sh /sbin/seafile-server

View File

@ -1,83 +0,0 @@
events {
worker_connections 12;
}
http{
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;
}
disable_symlinks off;
server {
listen 80;
error_log syslog:server=unix:/dev/log;
access_log syslog:server=unix:/dev/log;
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_pass http://files;
proxy_http_version 1.1;
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;
# }
}
}

14
nginx/backends.conf Normal file
View File

@ -0,0 +1,14 @@
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;
}

0
nginx/extra.conf Normal file
View File

22
nginx/nginx.conf Normal file
View File

@ -0,0 +1,22 @@
events {
worker_connections 64;
}
http {
include backends.conf;
disable_symlinks off;
server {
listen 80;
error_log /dev/stderr;
include seafile/*.conf;
include extra.conf;
}
}

0
nginx/seafile/media.conf Normal file
View File

View File

@ -0,0 +1,18 @@
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;
}

View File

@ -0,0 +1,10 @@
location /seafhttp {
rewrite ^/seafhttp(.*)$ $1 break;
proxy_pass http://files;
proxy_http_version 1.1;
client_max_body_size 0;
proxy_connect_timeout 3s;
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
send_timeout 3600s;
}

14
nginx/seafile/seahub.conf Normal file
View File

@ -0,0 +1,14 @@
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;
access_log /dev/stdout;
}

View File

@ -51,7 +51,7 @@ case "$1" in
mkdir -p $SEAF/conf mkdir -p $SEAF/conf
cp /etc/seafile/* $SEAF/conf/* -rf cp /etc/seafile/* $SEAF/conf/* -rf
$0 run-upgrade $0 run-upgrade
exit exit $?
else else
patch_seahub_conf patch_seahub_conf
for CMD in "${COMMANDS[@]}"; do for CMD in "${COMMANDS[@]}"; do
@ -81,6 +81,10 @@ case "$1" in
run-upgrade) run-upgrade)
$0 upgrade $0 upgrade
RES=$? RES=$?
if [ $RES -eq 1 ]; then
echo "Failed upgrade"
exit 1
fi
if [ $RES -eq 127 ]; then if [ $RES -eq 127 ]; then
#No upgrade #No upgrade
true true
@ -109,6 +113,28 @@ case "$1" in
/usr/local/sbin/upgrade main /usr/local/sbin/upgrade main
kill -SIGHUP $(pgrep -o nginx) #Reload nginx kill -SIGHUP $(pgrep -o nginx) #Reload nginx
;; ;;
maintanance)
$0 stop
if [ "$2" = "--fsck" ]; then
$LATEST/seaf-fsck.sh
fi
if [ "$2" = "--fsck-repair" ]; then
$LATEST/seaf-fsck.sh --repair
fi
$LATEST/seaf-gc.sh
$0 start
;;
setup)
INSTALLDIR=$2
SETUP_ARGS="auto -n ${SEAF_NAME:-$(hostname)} -i $(hostname) -p 8082"
if [ ! -z "$SEAF_MYSQL" ]; then
$INSTALLDIR/setup-seafile-mysql.sh $SETUP_ARGS -o $SEAF_MYSQL_HOST -t ${SEAF_MYSQL_PORT:-3306} -u "${SEAF_MYSQL_USER:-root}" \
-w "$SEAF_MYSQL_PASS" -r "${SEAF_MYSQL_ROOT_PASS:-$SEAF_MYSQL_PASS}" -c ${SEAF_MYSQL_DB_CCNET:-ccnet} -s ${SEAF_MYSQL_DB_SEAF:-seafile} \
-b ${SEAF_MYSQL_DB_HUB:-seahub}
else
$INSTALLDIR/setup-seafile.sh $SETUP_ARGS
fi
;;
status) status)
RUNNING=1 RUNNING=1
for CMD in seafile-controller ccnet "${COMMANDS[@]}"; do for CMD in seafile-controller ccnet "${COMMANDS[@]}"; do

View File

@ -37,6 +37,14 @@ def list_command(page="https://www.seafile.com/en/download/"):
def current_version_command(): def current_version_command():
print(current_version()) print(current_version())
def installed_versions():
installed = []
for f in os.listdir(seaf_home):
m = re.findall(version_re,f)
if len(m) > 0:
installed.append(m[0])
return installed
def current_version(): def current_version():
current = os.path.realpath(os.path.join(seaf_home, "seafile-server-latest")) current = os.path.realpath(os.path.join(seaf_home, "seafile-server-latest"))
res = re.findall(version_re,current) res = re.findall(version_re,current)
@ -49,10 +57,10 @@ def perform_upgrade_command(version,mysql=False,yes=True):
target = map(lambda x: int(x), version.split(".")) target = map(lambda x: int(x), version.split("."))
print len(current) == 1 and current[0] == 0 print len(current) == 1 and current[0] == 0
if len(current) == 1 and current[0] == 0: #Not installed if len(current) == 1 and current[0] == 0: #Not installed
print("Running installer, please don't change any default values regarding ports.") print("Running installer.")
installer = os.path.join(seaf_home,"seafile-server-%s" % version,"setup-seafile%s.sh" % ("-mysql" if mysql else "")) if not call(["seafile-server","setup", os.path.join(seaf_home,"seafile-server-%s" % version) ],stdout=sys.stdout, stdin=sys.stdin):
call(["sh","-c",installer],stdout=sys.stdout, stdin=sys.stdin) sys.exit(1)
return 0 sys.exit(126)
script_re = "^upgrade_(\d+).(\d+)_(\d+).(\d+)\.sh$" script_re = "^upgrade_(\d+).(\d+)_(\d+).(\d+)\.sh$"
run = [] run = []
last = None last = None
@ -70,20 +78,42 @@ def perform_upgrade_command(version,mysql=False,yes=True):
cmd.append(script) cmd.append(script)
call(["/bin/sh", "-c", ''.join(cmd)], stdout=sys.stdout, stdin=(None if yes else sys.stdin)) call(["/bin/sh", "-c", ''.join(cmd)], stdout=sys.stdout, stdin=(None if yes else sys.stdin))
def install_command(url): def download(url, version):
tmp = tempfile.mkdtemp() tmp = tempfile.mkdtemp()
if call(["/bin/sh", "-c", 'cd %s; curl %s | tar xzv' % (tmp, url)]) == 0: filename = "server_%s.tar.gz" % version
pks = os.path.join(seaf_home, "pkg")
if not os.path.exists(pks):
os.mkdir(pks)
dest = os.path.join(pks, filename)
if os.path.exists(dest):
return dest
if call(["/bin/sh", "-c", 'curl %s --output %s/%s' % (url, tmp, filename)]) == 0:
shutil.move(os.path.join(tmp,filename), dest)
call(["/bin/chmod", "-w", dest])
return dest
else:
print("Download failed")
return 0
def install_command(url, version):
pkg = download(url, version)
tmp = tempfile.mkdtemp()
if pkg and call(["/bin/sh", "-c", 'cd %s; tar xzvf %s' % (tmp, pkg)]) == 0:
for f in os.listdir(tmp): for f in os.listdir(tmp):
dest = os.path.join(seaf_home, os.path.basename(f))
if len(re.findall(version_re, f)) > 0: if len(re.findall(version_re, f)) > 0:
dest = os.path.join(seaf_home, os.path.basename(f)) if not os.path.exists(dest):
shutil.move(os.path.join(tmp,f), dest) shutil.move(os.path.join(tmp,f), dest)
else:
shutil.rmtree(tmp)
print("Found previous installation, resuming setup")
current = current_version() current = current_version()
target_version = ''.join(re.findall(version_re,dest)) target_version = ''.join(re.findall(version_re,dest))
if len(current) == 1: current = current[0] if len(current) == 1: current = current[0]
else: current = "0.0.0" else: current = "0.0.0"
print("Upgrading from: %s -> %s" % (current, target_version)) print("Upgrading from: %s -> %s" % (current, target_version))
perform_upgrade_command(target_version,mysql=(os.environ["SEAF_MYSQL"] or False)) perform_upgrade_command(target_version,mysql=("SEAF_MYSQL" in os.environ and os.environ["SEAF_MYSQL"]))
if len(os.listdir(tmp)) != 0: if os.path.exists(tmp) and len(os.listdir(tmp)) != 0:
print("Failed to unpack update") print("Failed to unpack update")
os.rmdir(tmp) os.rmdir(tmp)
return 1 return 1
@ -95,19 +125,21 @@ def main_command(version="latest",page="https://www.seafile.com/en/download/"):
avail = available(page) avail = available(page)
install = None install = None
if version == "latest": if version == "latest":
(install,version) = avail.items() (version,install) = avail.items()[0]
else: else:
if version in dict(avail.items()): if version in dict(avail.items()):
install = dict(avail.items())[version] install = dict(avail.items())[version]
if version_int(current_version()) == version_int(version): if version_int(current_version()) == version_int(version):
print("%s(%s) is already installed" % (version,version_int(version))) print("%s(%s) is already installed" % (version,version_int(version)))
return 1 sys.exit(126)
if version in installed_versions():
return perform_upgrade_command(version)
if install: if install:
print("Installing: %s" % install[1]) print("Installing: %s" % version)
return install_command(install[1]) sys.exit(install_command(install, version))
else: else:
print("Couldn't determine download for %s" % version) print("Couldn't determine download for %s" % version)
return 1 sys.exit(1)
if __name__ == '__main__': if __name__ == '__main__':
import scriptine import scriptine

31
seafile.service Normal file
View File

@ -0,0 +1,31 @@
[Unit]
Description=Seafile container https://git.shimun.net/shimun/docker-seafile
[Service]
Slice=machine.slice
# Resource limits
Delegate=true
CPUShares=256
MemoryLimit=512M
Environment=ROOT_DIR=/srv/seafile
Environment=SEAF_MYSQL="" #Empty = Sqlite
Environment=SEAF_URL="https://seaf.example.com"
Environment=SEAF_UPGRADE_INTERVAL=10
#Run first once to setup
#rkt --insecure-options=image run --dns 8.8.8.8 --volume volume-opt-seafile,kind=host,source=${ROOT_DIR} docker://repo.shimun.net/shimun/seafile --environment=SEAF_URL="https://seaf.example.com" --interactive
ExecStartPre=/bin/mkdir -p ${ROOT_DIR}
ExecStart=/usr/bin/rkt --insecure-options=image run --uuid-file-save=${ROOT_DIR}/container.uuid --dns 8.8.8.8 --inherit-env --volume volume-opt-seafile,kind=host,source=${ROOT_DIR} --port 80-tcp:8080 \
docker://repo.shimun.net/shimun/seafile --environment=SEAF_UPGRADE_INTERVAL=${SEAF_UPGRADE_INTERVAL}
ExecStartPost=/bin/bash -c "echo 'rkt enter --app=seafile $(cat '${ROOT_DIR}'/container.uuid)' > ${ROOT_DIR}/enter.sh && chmod +x ${ROOT_DIR}/enter.sh"
ExecStopPre=/bin/bash -c "rkt enter --app=seafile $(cat ${ROOT_DIR}/container.uuid) 'seafile-server stop'"
ExecStopPost=/bin/bash -c "rkt rm $(cat ${ROOT_DIR}/container.uuid)"
ExecStopPost=/bin/rm ${ROOT_DIR}/container.uuid
KillMode=mixed
Restart=always
RestartSec=30
[Install]
WantedBy=multi-user.target