2016-11-12 03:28:49 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#coding: UTF-8
|
|
|
|
|
|
|
|
"""
|
2016-11-29 09:13:06 +00:00
|
|
|
Starts the seafile/seahub server and watches the controller process. It is
|
|
|
|
the entrypoint command of the docker container.
|
2016-11-12 03:28:49 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
import json
|
|
|
|
import os
|
|
|
|
from os.path import abspath, basename, exists, dirname, join, isdir
|
|
|
|
import shutil
|
|
|
|
import sys
|
2016-11-14 00:31:39 +00:00
|
|
|
import time
|
2016-11-12 03:28:49 +00:00
|
|
|
|
2016-11-29 06:44:26 +00:00
|
|
|
from utils import (
|
|
|
|
call, get_conf, get_install_dir, get_script, get_command_output,
|
|
|
|
render_template, wait_for_mysql
|
|
|
|
)
|
2016-11-12 03:28:49 +00:00
|
|
|
|
|
|
|
installdir = get_install_dir()
|
|
|
|
topdir = dirname(installdir)
|
|
|
|
|
2016-11-14 00:31:39 +00:00
|
|
|
def watch_controller():
|
|
|
|
maxretry = 4
|
|
|
|
retry = 0
|
|
|
|
while retry < maxretry:
|
2017-06-06 10:23:12 +00:00
|
|
|
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:
|
2016-11-14 00:31:39 +00:00
|
|
|
retry += 1
|
2016-11-29 09:13:06 +00:00
|
|
|
else:
|
|
|
|
retry = 0
|
|
|
|
time.sleep(5)
|
2016-11-14 00:31:39 +00:00
|
|
|
print 'seafile controller exited unexpectedly.'
|
|
|
|
sys.exit(1)
|
|
|
|
|
2016-11-12 03:28:49 +00:00
|
|
|
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)
|
|
|
|
|
2016-11-29 06:44:26 +00:00
|
|
|
wait_for_mysql()
|
2016-11-15 04:11:58 +00:00
|
|
|
|
2016-11-12 03:28:49 +00:00
|
|
|
try:
|
2016-11-15 04:11:58 +00:00
|
|
|
call('{} start'.format(get_script('seafile.sh')))
|
|
|
|
call('{} start'.format(get_script('seahub.sh')))
|
2016-11-12 03:28:49 +00:00
|
|
|
finally:
|
|
|
|
if exists(password_file):
|
|
|
|
os.unlink(password_file)
|
|
|
|
|
2016-11-14 06:47:40 +00:00
|
|
|
print 'seafile server is running now.'
|
|
|
|
try:
|
|
|
|
watch_controller()
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
print 'Stopping seafile server.'
|
|
|
|
sys.exit(0)
|
2016-11-14 00:31:39 +00:00
|
|
|
|
2016-11-12 03:28:49 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|