2021-01-17 23:45:50 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
#coding: UTF-8
|
|
|
|
|
2021-01-18 15:21:40 +00:00
|
|
|
"""
|
|
|
|
Starts the seafile/seahub server and watches the controller process. It is
|
|
|
|
the entrypoint command of the docker container.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import json
|
2021-01-17 23:45:50 +00:00
|
|
|
import os
|
2021-01-18 15:21:40 +00:00
|
|
|
from os.path import abspath, basename, exists, dirname, join, isdir
|
|
|
|
import shutil
|
2021-01-17 23:45:50 +00:00
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
|
2021-01-18 15:21:40 +00:00
|
|
|
from utils import (
|
2021-01-18 23:50:01 +00:00
|
|
|
call, get_conf, get_install_dir, get_script, get_command_output, wait_for_mysql, setup_logging
|
2021-01-18 15:21:40 +00:00
|
|
|
)
|
2021-01-17 23:45:50 +00:00
|
|
|
from upgrade import check_upgrade
|
2021-01-18 23:50:01 +00:00
|
|
|
from bootstrap import init_seafile_server
|
2021-01-18 15:21:40 +00:00
|
|
|
|
2021-01-17 23:45:50 +00:00
|
|
|
|
2021-01-18 15:21:40 +00:00
|
|
|
shared_seafiledir = '/shared/seafile'
|
|
|
|
ssl_dir = '/shared/ssl'
|
|
|
|
generated_dir = '/bootstrap/generated'
|
2021-01-17 23:45:50 +00:00
|
|
|
installdir = get_install_dir()
|
|
|
|
topdir = dirname(installdir)
|
|
|
|
|
|
|
|
def watch_controller():
|
|
|
|
maxretry = 4
|
|
|
|
retry = 0
|
|
|
|
while retry < maxretry:
|
|
|
|
controller_pid = get_command_output('ps aux | grep seafile-controller | grep -v grep || true').strip()
|
|
|
|
garbage_collector_pid = get_command_output('ps aux | grep /scripts/gc.sh | grep -v grep || true').strip()
|
|
|
|
if not controller_pid and not garbage_collector_pid:
|
|
|
|
retry += 1
|
|
|
|
else:
|
|
|
|
retry = 0
|
|
|
|
time.sleep(5)
|
|
|
|
print('seafile controller exited unexpectedly.')
|
|
|
|
sys.exit(1)
|
|
|
|
|
2021-01-20 01:24:17 +00:00
|
|
|
# Modifiy gunicorn.conf.py
|
|
|
|
# Make gunicorn bind to "0.0.0.0:8000" instead of "127.0.0.1:8000".
|
|
|
|
# Otherwise external connections will be refused.
|
|
|
|
def fix_gunicorn_bind():
|
|
|
|
if os.path.exists(join(shared_seafiledir, 'conf', 'gunicorn.conf.py')):
|
|
|
|
with open(join(shared_seafiledir, 'conf', 'gunicorn.conf.py'), 'r') as fp:
|
|
|
|
fp_lines = fp.readlines()
|
2021-01-21 01:33:38 +00:00
|
|
|
if 'bind = "127.0.0.1:8000"\n' in fp_lines:
|
|
|
|
replace_index = fp_lines.index('bind = "127.0.0.1:8000"\n')
|
|
|
|
replace_line = 'bind = "0.0.0.0:8000"\n'
|
|
|
|
fp_lines[replace_index] = replace_line
|
2021-01-20 01:24:17 +00:00
|
|
|
|
|
|
|
with open(join(shared_seafiledir, 'conf', 'gunicorn.conf.py'), 'w') as fp:
|
|
|
|
fp.writelines(fp_lines)
|
|
|
|
|
|
|
|
|
2021-01-18 15:21:40 +00:00
|
|
|
def main():
|
|
|
|
if not exists(shared_seafiledir):
|
|
|
|
os.mkdir(shared_seafiledir)
|
|
|
|
if not exists(generated_dir):
|
|
|
|
os.makedirs(generated_dir)
|
|
|
|
|
|
|
|
wait_for_mysql()
|
|
|
|
init_seafile_server()
|
|
|
|
|
|
|
|
check_upgrade()
|
2021-01-17 23:45:50 +00:00
|
|
|
os.chdir(installdir)
|
|
|
|
|
2021-01-20 01:24:17 +00:00
|
|
|
fix_gunicorn_bind()
|
|
|
|
|
2021-01-27 23:40:14 +00:00
|
|
|
call('{} start'.format(get_script('seafile.sh')))
|
|
|
|
|
2021-01-17 23:45:50 +00:00
|
|
|
print('seafile server is running now.')
|
|
|
|
try:
|
|
|
|
watch_controller()
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
print('Stopping seafile server.')
|
|
|
|
sys.exit(0)
|
|
|
|
|
2021-01-18 15:21:40 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
setup_logging()
|
|
|
|
main()
|