From 2dc6f8d5bcdadd820ef108ffe2ce288cf82da338 Mon Sep 17 00:00:00 2001 From: Shuai Lin Date: Mon, 14 Nov 2016 08:31:39 +0800 Subject: [PATCH] Make the start.py script run forever in foreground. --- launcher | 4 +++- scripts/start.py | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/launcher b/launcher index 389aadc..be87f50 100755 --- a/launcher +++ b/launcher @@ -65,7 +65,9 @@ bootstrap() { start() { set_volumes - docker run --rm -it --name seafile $volumes $image /scripts/start.py + docker run --rm -it --name seafile $volumes $image \ + /sbin/my_init -- /scripts/start.py + # /sbin/my_init -- bash -l } enter() { diff --git a/scripts/start.py b/scripts/start.py index 23bd732..94a58cd 100755 --- a/scripts/start.py +++ b/scripts/start.py @@ -12,12 +12,24 @@ 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 +from utils import call, get_conf, get_install_dir, get_script, get_command_output 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() + if not controller_pid: + retry += 1 + time.sleep(2) + print 'seafile controller exited unexpectedly.' + sys.exit(1) + def main(): admin_pw = { 'email': get_conf('admin.email'), @@ -34,5 +46,7 @@ def main(): if exists(password_file): os.unlink(password_file) + watch_controller() + if __name__ == '__main__': main()