mirror of
https://github.com/ggogel/seafile-containerized.git
synced 2024-11-16 17:05:32 +00:00
702f5da610
* Add garbage collector command to launcher The seafile garbage collector can be started via the 'gc' command option of the launcher. This will stop the seafile-server inside the container, then run the 'seaf-gc.sh' script and redirect its output to '/var/log/gc.log'. Afterwards the whole container will be restarted. * Move garbage collector execution logic to scripts/gc.sh The file gc.sh stops the seafile server, starts the garbage collector and restarts the seafile server when the cleanup is finished. The output of the 'seaf-gc.sh' script is piped to the file '/var/log/gc.log' in append mode. * Add 'scripts/gc.sh' to watch_controller function in 'scripts/start.py' The 'start.py' script monitors the seafile-server in a 'watch_controller' function and terminates the container when the server crashed. However, during a garbage collector cleanup the server needs to be shut down and therefore it is necessary that the 'watch_controller' function only terminates the container if the server is offline and no cleanup is in progress. * Add the gc command info to README * Preseve the exit code of seaf-gc.sh * Fix the perm of scripts/gc.sh
65 lines
1.7 KiB
Python
Executable file
65 lines
1.7 KiB
Python
Executable file
#!/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
|
|
)
|
|
|
|
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)
|
|
|
|
def main():
|
|
admin_pw = {
|
|
'email': get_conf('admin.email'),
|
|
'password': get_conf('admin.password'),
|
|
}
|
|
password_file = join(topdir, 'conf', 'admin.txt')
|
|
with open(password_file, 'w') as fp:
|
|
json.dump(admin_pw, fp)
|
|
|
|
wait_for_mysql()
|
|
|
|
try:
|
|
call('{} start'.format(get_script('seafile.sh')))
|
|
call('{} start'.format(get_script('seahub.sh')))
|
|
finally:
|
|
if exists(password_file):
|
|
os.unlink(password_file)
|
|
|
|
print 'seafile server is running now.'
|
|
try:
|
|
watch_controller()
|
|
except KeyboardInterrupt:
|
|
print 'Stopping seafile server.'
|
|
sys.exit(0)
|
|
|
|
if __name__ == '__main__':
|
|
main()
|