From 12412e733d4aaf6dc064ab5796beae331c874e23 Mon Sep 17 00:00:00 2001 From: Shuai Lin Date: Tue, 29 Nov 2016 15:09:16 +0800 Subject: [PATCH] Suppport verbose mode: "./launcher -v " --- launcher | 37 +++++++++++++++++++++++++++++-------- scripts/bootstrap.py | 9 +++++---- scripts/utils/__init__.py | 9 +++++++++ 3 files changed, 43 insertions(+), 12 deletions(-) diff --git a/launcher b/launcher index c5bd2ed..ff42ff6 100755 --- a/launcher +++ b/launcher @@ -21,7 +21,7 @@ usage () { set -e set -o pipefail -version=6.1.0 +version=6.0.5 image=seafileorg/server:$version local_image=local_seafile/server:latest dockerdir=$(cd "$(dirname $0)"; pwd -P) @@ -32,9 +32,9 @@ version_stamp_file=$sharedir/seafile/seafile-data/current_version cd $dockerdir -dbg() { - if [[ $debug == "true" ]]; then - echo "dbg: $1" +dlog() { + if [[ $verbose == "true" ]]; then + show_progress "[debug] $1" fi } @@ -76,6 +76,13 @@ init_shared() { fi } +set_envs() { + envs="" + if [[ $verbose == "true" ]]; then + envs="$envs -e SEAFILE_DOCKER_VERBOSE=true" + fi +} + set_ports() { ports=$(docker run $user_args --rm -it \ -v ${dockerdir}/scripts:/scripts \ @@ -138,10 +145,11 @@ bootstrap() { } # First initialize seafile server and letsencrypt + set_envs set_bootstrap_volumes set_ports - docker run $user_args --rm -it --name seafile-bootstrap -e SEAFILE_BOOTSRAP=1 $volumes $ports $image /sbin/my_init -- /scripts/bootstrap.py + docker run $user_args --rm -it --name seafile-bootstrap -e SEAFILE_BOOTSRAP=1 $envs $volumes $ports $image /sbin/my_init $quiet -- /scripts/bootstrap.py show_progress "Now building the local docker image." docker build -f bootstrap/generated/Dockerfile -t local_seafile/server:latest . >/dev/null @@ -169,6 +177,7 @@ start() { exit 0 fi + set_envs set_volumes set_ports @@ -183,7 +192,7 @@ start() { show_progress "Starting up new seafile server container" ( set -x - docker run $user_args $attach_on_run $restart_policy --name seafile -h seafile $volumes $ports $local_image + docker run $user_args $attach_on_run $restart_policy --name seafile -h seafile $envs $volumes $ports $local_image ) } @@ -253,6 +262,8 @@ check_version_match() { last_major_version=$(get_major_version $last_version) current_major_version=$(get_major_version $version) + dlog "Your version: ${last_version}, latest version: ${version}" + if [[ $last_major_version != "$current_major_version" ]]; then show_progress "******* Major upgrade detected *******" show_progress "You have $last_version, latest is $version" @@ -295,13 +306,14 @@ _launch_for_upgrade() { cmd="/bin/bash" fi + set_envs set_volumes ( set -x docker run $user_args \ -it --rm --name seafile-upgrade -h seafile \ - $volumes $local_image \ - /sbin/my_init -- $cmd + $envs $volumes $local_image \ + /sbin/my_init $quiet -- $cmd ) } @@ -376,6 +388,8 @@ main() { case "$1" in bootstrap|start|stop|restart|enter|destroy|logs|rebuild|manual-upgrade) action=${1//-/_} ; shift 1 ;; + -h|--help) ( usage ; exit 1) ; shift 1 ;; + -v|--verbose) verbose=true ; shift 1 ;; --skip-prereqs) SKIP_PREREQS=true ; shift 1 ;; --docker-args) user_args=$2 ; shift 2 ;; --manual-upgrade) use_manual_upgrade=true ; shift 1 ;; @@ -383,6 +397,13 @@ main() { esac done + # By default we suppress the verbose logs like "Running + # /etc/my_init.d/99_mysql_setup.sh". Use "./launcher -v " to enable + # printing of these verbose logs. + quiet="--quiet" + if [[ $verbose == "true" ]]; then + quiet="" + fi "$action" } diff --git a/scripts/bootstrap.py b/scripts/bootstrap.py index a2ea919..d9689c3 100755 --- a/scripts/bootstrap.py +++ b/scripts/bootstrap.py @@ -18,7 +18,8 @@ import time from utils import ( call, get_conf, get_install_dir, show_progress, get_script, render_template, get_seafile_version, eprint, - cert_has_valid_days, get_version_stamp_file, update_version_stamp + cert_has_valid_days, get_version_stamp_file, update_version_stamp, + wait_for_mysql, wait_for_nginx ) seafile_version = get_seafile_version() @@ -61,9 +62,7 @@ def init_letsencrypt(): render_template('/templates/seafile.nginx.conf.template', '/etc/nginx/sites-enabled/seafile.nginx.conf', context) - # TODO: The 5 seconds heuristic is not good, how can we know for sure nginx is ready? - print 'waiting for nginx server to be ready' - time.sleep(5) + wait_for_nginx() call('nginx -s reload') call('/scripts/ssl.sh {0} {1}'.format(ssl_dir, domain)) @@ -156,6 +155,7 @@ def init_seafile_server(): if not exists(dst) and exists(src): shutil.move(src, shared_seafiledir) + show_progress('Updating version stamp') update_version_stamp(version_stamp_file, os.environ['SEAFILE_VERSION']) def main(): @@ -174,6 +174,7 @@ def main(): init_letsencrypt() generate_local_nginx_conf() + wait_for_mysql() init_seafile_server() show_progress('Generated local config.') diff --git a/scripts/utils/__init__.py b/scripts/utils/__init__.py index 9c53408..dd070d9 100644 --- a/scripts/utils/__init__.py +++ b/scripts/utils/__init__.py @@ -267,6 +267,15 @@ def wait_for_mysql(): time.sleep(2) print('mysql server is ready') +def wait_for_nginx(): + while True: + print('waiting for nginx server to be ready') + output = get_command_output('netstat -nltp') + if ':80 ' in output: + print('nginx is ready') + return + time.sleep(2) + def replace_file_pattern(fn, pattern, replacement): with open(fn, 'r') as fp: content = fp.read()