remove db && cluster mode

This commit is contained in:
root 2018-05-18 09:12:14 +00:00 committed by Hu
parent 838b73e1e4
commit e6f6d9c2d2
12 changed files with 1566 additions and 132 deletions

View file

@ -26,7 +26,7 @@ base:
docker rmi `docker images --filter "dangling=true" -q --no-trunc`
server:
cd seafile && cp -rf ../../scripts ./ && docker build -t $(server_image) .
cd seafile && cp -rf ../../templates ./ && cp -rf ../../scripts ./ && docker build -t $(server_image) .
docker-squash --tag $(server_image_squashed) $(server_image) --from-layer=$(base_image)
docker tag $(server_image_squashed) $(server_image)
docker tag $(server_image) $(latest_server_image)
@ -39,7 +39,7 @@ pro-base:
docker rmi `docker images --filter "dangling=true" -q --no-trunc`
pro-server:
cd pro_seafile && cp -rf ../../scripts ./ && docker build -t $(pro_server_image) .
cd pro_seafile && cp -rf ../../templates ./ && cp -rf ../../scripts ./ && docker build -t $(pro_server_image) .
docker-squash --tag $(pro_server_image_squashed) $(pro_server_image) --from-layer=$(pro_base_image)
docker tag $(pro_server_image_squashed) $(pro_server_image)
docker tag $(pro_server_image) $(latest_pro_server_image)

View file

@ -7,7 +7,7 @@ ENV UPDATED_AT=20180412 \
CMD ["/sbin/my_init", "--", "bash", "-l"]
RUN apt-get update -qq && apt-get -qq -y install memcached mariadb-server nginx
RUN apt-get update -qq && apt-get -qq -y install memcached nginx tzdata
# Utility tools
RUN apt-get install -qq -y vim htop net-tools psmisc git wget curl
@ -26,19 +26,12 @@ RUN pip install -r /tmp/requirements.txt
COPY services /services
RUN mkdir -p /etc/service/memcached && \
mv /services/memcached.sh /etc/service/memcached/run
RUN mkdir -p /etc/service/nginx && \
rm -f /etc/nginx/sites-enabled/* /etc/nginx/conf.d/* && \
mv /services/nginx.conf /etc/nginx/nginx.conf && \
mv /services/nginx.sh /etc/service/nginx/run
RUN mkdir -p /etc/service/mysql && \
mv /services/mysql.sh /etc/service/mysql/run
RUN mkdir -p /etc/my_init.d && rm -f /etc/my_init.d/00_regen_ssh_host_keys.sh
ADD my_init.d/99_mysql_setup.sh /etc/my_init.d/
# Clean up for docker squash
# See https://github.com/goldmann/docker-squash

View file

@ -14,5 +14,4 @@ ADD scripts/create_data_links.sh /etc/my_init.d/01_create_data_links.sh
COPY scripts /scripts
COPY templates /templates
CMD ["/sbin/my_init", "--", "/scripts/start.py"]
RUN chmod u+x /scripts/*

View file

@ -1,3 +0,0 @@
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# min hour dayofmonth month dayofweek command
0 0 1 * * root /scripts/ssl.sh {{ ssl_dir }} {{ domain }}

View file

@ -1,81 +0,0 @@
# -*- mode: nginx -*-
# Auto generated at {{ current_timestr }}
{% if https -%}
server {
listen 80;
server_name _ default_server;
rewrite ^ https://{{ domain }}$request_uri? permanent;
}
{% endif -%}
server {
{% if https -%}
listen 443;
ssl on;
ssl_certificate /shared/ssl/{{ domain }}.crt;
ssl_certificate_key /shared/ssl/{{ domain }}.key;
ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS;
# TODO: More SSL security hardening: ssl_session_tickets & ssl_dhparam
# ssl_session_tickets on;
# ssl_session_ticket_key /etc/nginx/sessionticket.key;
# ssl_session_cache shared:SSL:10m;
# ssl_session_timeout 10m;
{% else -%}
listen 80;
{% endif -%}
server_name {{ domain }};
client_max_body_size 10m;
location / {
proxy_pass http://127.0.0.1:8000/;
proxy_read_timeout 310s;
proxy_set_header Host $host;
proxy_set_header Forwarded "for=$remote_addr;proto=$scheme";
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Connection "";
proxy_http_version 1.1;
}
location /seafhttp {
rewrite ^/seafhttp(.*)$ $1 break;
proxy_pass http://127.0.0.1:8082;
client_max_body_size 0;
proxy_connect_timeout 36000s;
proxy_read_timeout 36000s;
}
location /seafdav {
client_max_body_size 0;
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;
access_log /var/log/nginx/seafdav.access.log;
error_log /var/log/nginx/seafdav.error.log;
}
location /media {
root /opt/seafile/seafile-server-latest/seahub;
}
# For letsencrypt
location /.well-known/acme-challenge/ {
alias /var/www/challenges/;
try_files $uri =404;
}
}

View file

@ -66,6 +66,16 @@ fi
ln -sf /shared/db /var/lib/mysql
if [[ ! -e /shared/logs/var-log ]]; then
chmod 777 /var/log -R
mv /var/log /shared/logs/var-log
fi
rm -rf /var/log && ln -sf /shared/logs/var-log /var/log
if [[ ! -e latest_version_dir ]]; then
ln -sf $current_version_dir $latest_version_dir
fi
chmod u+x /scripts/*
echo $PYTHON
$PYTHON /scripts/init.py

46
scripts/init.py Executable file
View file

@ -0,0 +1,46 @@
#!/usr/bin/env python
#coding: UTF-8
"""
Starts the seafile/seahub server and watches the controller process. It is
the entrypoint command of the docker container.
"""
import json
import os
from os.path import abspath, basename, exists, dirname, join, isdir
import shutil
import sys
import time
from utils import (
call, get_conf, get_install_dir, get_script, get_command_output,
render_template, wait_for_mysql
)
from upgrade import check_upgrade
from bootstrap import init_seafile_server, is_https, init_letsencrypt, generate_local_nginx_conf
shared_seafiledir = '/shared/seafile'
ssl_dir = '/shared/ssl'
generated_dir = '/bootstrap/generated'
installdir = get_install_dir()
topdir = dirname(installdir)
def main():
call('cp -rf /scripts/setup-seafile-mysql.py ' + join(installdir, 'setup-seafile-mysql.py'))
if not exists(shared_seafiledir):
os.mkdir(shared_seafiledir)
if not exists(generated_dir):
os.makedirs(generated_dir)
if is_https():
init_letsencrypt()
generate_local_nginx_conf()
if not exists(join(shared_seafiledir, 'conf')):
init_seafile_server()
if __name__ == '__main__':
main()

1497
scripts/setup-seafile-mysql.py Executable file

File diff suppressed because it is too large Load diff

View file

@ -1,29 +1,11 @@
#!/usr/bin/env python
#coding: UTF-8
"""
Starts the seafile/seahub server and watches the controller process. It is
the entrypoint command of the docker container.
"""
import json
import os
from os.path import abspath, basename, exists, dirname, join, isdir
import shutil
import sys
import time
import json
from os.path import join, exists, dirname
from utils import (
call, get_conf, get_install_dir, get_script, get_command_output,
render_template, wait_for_mysql
)
from upgrade import check_upgrade
from bootstrap import init_seafile_server, is_https, init_letsencrypt, generate_local_nginx_conf
from utils import call, get_conf, get_script, get_command_output, get_install_dir
shared_seafiledir = '/shared/seafile'
ssl_dir = '/shared/ssl'
generated_dir = '/bootstrap/generated'
installdir = get_install_dir()
topdir = dirname(installdir)
@ -42,28 +24,17 @@ def watch_controller():
sys.exit(1)
def main():
if not exists(shared_seafiledir):
os.mkdir(shared_seafiledir)
if not exists(generated_dir):
os.makedirs(generated_dir)
if is_https():
init_letsencrypt()
generate_local_nginx_conf()
call('nginx -s reload')
wait_for_mysql()
init_seafile_server()
call('/scripts/create_data_links.sh')
check_upgrade()
os.chdir(installdir)
call('service nginx start &')
admin_pw = {
'email': get_conf('SEAFILE_ADMIN_EMAIL', 'me@example.com'),
'password': get_conf('SEAFILE_ADMIN_PASSWORD', 'asecret'),
}
password_file = join(topdir, 'conf', 'admin.txt')
with open(password_file, 'w') as fp:
with open(password_file, 'w+') as fp:
json.dump(admin_pw, fp)
@ -81,5 +52,5 @@ def main():
print 'Stopping seafile server.'
sys.exit(0)
if __name__ == '__main__':
if __name__ == "__main__":
main()

2
scripts/start.sh Executable file
View file

@ -0,0 +1,2 @@
#!/bin/bash
python /scripts/start.py