Suppport verbose mode: "./launcher -v <cmd>"

This commit is contained in:
Shuai Lin 2016-11-29 15:09:16 +08:00
parent e6a0840cf0
commit 12412e733d
3 changed files with 43 additions and 12 deletions

View file

@ -21,7 +21,7 @@ usage () {
set -e set -e
set -o pipefail set -o pipefail
version=6.1.0 version=6.0.5
image=seafileorg/server:$version image=seafileorg/server:$version
local_image=local_seafile/server:latest local_image=local_seafile/server:latest
dockerdir=$(cd "$(dirname $0)"; pwd -P) dockerdir=$(cd "$(dirname $0)"; pwd -P)
@ -32,9 +32,9 @@ version_stamp_file=$sharedir/seafile/seafile-data/current_version
cd $dockerdir cd $dockerdir
dbg() { dlog() {
if [[ $debug == "true" ]]; then if [[ $verbose == "true" ]]; then
echo "dbg: $1" show_progress "[debug] $1"
fi fi
} }
@ -76,6 +76,13 @@ init_shared() {
fi fi
} }
set_envs() {
envs=""
if [[ $verbose == "true" ]]; then
envs="$envs -e SEAFILE_DOCKER_VERBOSE=true"
fi
}
set_ports() { set_ports() {
ports=$(docker run $user_args --rm -it \ ports=$(docker run $user_args --rm -it \
-v ${dockerdir}/scripts:/scripts \ -v ${dockerdir}/scripts:/scripts \
@ -138,10 +145,11 @@ bootstrap() {
} }
# First initialize seafile server and letsencrypt # First initialize seafile server and letsencrypt
set_envs
set_bootstrap_volumes set_bootstrap_volumes
set_ports 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." show_progress "Now building the local docker image."
docker build -f bootstrap/generated/Dockerfile -t local_seafile/server:latest . >/dev/null docker build -f bootstrap/generated/Dockerfile -t local_seafile/server:latest . >/dev/null
@ -169,6 +177,7 @@ start() {
exit 0 exit 0
fi fi
set_envs
set_volumes set_volumes
set_ports set_ports
@ -183,7 +192,7 @@ start() {
show_progress "Starting up new seafile server container" show_progress "Starting up new seafile server container"
( (
set -x 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) last_major_version=$(get_major_version $last_version)
current_major_version=$(get_major_version $version) current_major_version=$(get_major_version $version)
dlog "Your version: ${last_version}, latest version: ${version}"
if [[ $last_major_version != "$current_major_version" ]]; then if [[ $last_major_version != "$current_major_version" ]]; then
show_progress "******* Major upgrade detected *******" show_progress "******* Major upgrade detected *******"
show_progress "You have $last_version, latest is $version" show_progress "You have $last_version, latest is $version"
@ -295,13 +306,14 @@ _launch_for_upgrade() {
cmd="/bin/bash" cmd="/bin/bash"
fi fi
set_envs
set_volumes set_volumes
( (
set -x set -x
docker run $user_args \ docker run $user_args \
-it --rm --name seafile-upgrade -h seafile \ -it --rm --name seafile-upgrade -h seafile \
$volumes $local_image \ $envs $volumes $local_image \
/sbin/my_init -- $cmd /sbin/my_init $quiet -- $cmd
) )
} }
@ -376,6 +388,8 @@ main() {
case "$1" in case "$1" in
bootstrap|start|stop|restart|enter|destroy|logs|rebuild|manual-upgrade) bootstrap|start|stop|restart|enter|destroy|logs|rebuild|manual-upgrade)
action=${1//-/_} ; shift 1 ;; action=${1//-/_} ; shift 1 ;;
-h|--help) ( usage ; exit 1) ; shift 1 ;;
-v|--verbose) verbose=true ; shift 1 ;;
--skip-prereqs) SKIP_PREREQS=true ; shift 1 ;; --skip-prereqs) SKIP_PREREQS=true ; shift 1 ;;
--docker-args) user_args=$2 ; shift 2 ;; --docker-args) user_args=$2 ; shift 2 ;;
--manual-upgrade) use_manual_upgrade=true ; shift 1 ;; --manual-upgrade) use_manual_upgrade=true ; shift 1 ;;
@ -383,6 +397,13 @@ main() {
esac esac
done done
# By default we suppress the verbose logs like "Running
# /etc/my_init.d/99_mysql_setup.sh". Use "./launcher -v <cmd>" to enable
# printing of these verbose logs.
quiet="--quiet"
if [[ $verbose == "true" ]]; then
quiet=""
fi
"$action" "$action"
} }

View file

@ -18,7 +18,8 @@ import time
from utils import ( from utils import (
call, get_conf, get_install_dir, show_progress, call, get_conf, get_install_dir, show_progress,
get_script, render_template, get_seafile_version, eprint, 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() seafile_version = get_seafile_version()
@ -61,9 +62,7 @@ def init_letsencrypt():
render_template('/templates/seafile.nginx.conf.template', render_template('/templates/seafile.nginx.conf.template',
'/etc/nginx/sites-enabled/seafile.nginx.conf', context) '/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? wait_for_nginx()
print 'waiting for nginx server to be ready'
time.sleep(5)
call('nginx -s reload') call('nginx -s reload')
call('/scripts/ssl.sh {0} {1}'.format(ssl_dir, domain)) 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): if not exists(dst) and exists(src):
shutil.move(src, shared_seafiledir) shutil.move(src, shared_seafiledir)
show_progress('Updating version stamp')
update_version_stamp(version_stamp_file, os.environ['SEAFILE_VERSION']) update_version_stamp(version_stamp_file, os.environ['SEAFILE_VERSION'])
def main(): def main():
@ -174,6 +174,7 @@ def main():
init_letsencrypt() init_letsencrypt()
generate_local_nginx_conf() generate_local_nginx_conf()
wait_for_mysql()
init_seafile_server() init_seafile_server()
show_progress('Generated local config.') show_progress('Generated local config.')

View file

@ -267,6 +267,15 @@ def wait_for_mysql():
time.sleep(2) time.sleep(2)
print('mysql server is ready') 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): def replace_file_pattern(fn, pattern, replacement):
with open(fn, 'r') as fp: with open(fn, 'r') as fp:
content = fp.read() content = fp.read()