From 63dd4b5c19f263ae98974956e3d05ab7cbfec759 Mon Sep 17 00:00:00 2001 From: Shuai Lin Date: Fri, 25 Nov 2016 12:33:10 +0800 Subject: [PATCH] Added launcher rebuild command. --- launcher | 53 ++++++++++++++++++++++++++++++++++- templates/Dockerfile.template | 3 +- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/launcher b/launcher index 85d94eb..8812327 100755 --- a/launcher +++ b/launcher @@ -214,7 +214,58 @@ destroy() { } rebuild() { - err_and_quit "Not implemented yet" + if [[ "$(git symbolic-ref --short HEAD)" == "master" ]]; then + echo "Ensuring launcher is up to date" + + git remote update + + LOCAL=$(git rev-parse @) + REMOTE=$(git rev-parse "@{u}") + BASE=$(git merge-base @ "@{u}") + + if [[ $LOCAL = "$REMOTE" ]]; then + echo "Launcher is up-to-date" + + elif [[ $LOCAL = "$BASE" ]]; then + echo "Updating Launcher" + git pull || (echo 'failed to update' && exit 1) + + for (( i=${#BASH_ARGV[@]}-1,j=0; i>=0,j<${#BASH_ARGV[@]}; i--,j++ )) + do + args[$j]=${BASH_ARGV[$i]} + done + exec /bin/bash $0 "${args[@]}" # $@ is empty, because of shift at the beginning. Use BASH_ARGV instead. + + elif [[ $REMOTE = "$BASE" ]]; then + echo "Your version of Launcher is ahead of origin" + else + echo "Launcher has diverged source, this is only expected in Dev mode" + fi + + fi + + set_existing_container + + if [[ $existing != "" ]]; then + echo "Stopping old container" + ( + set -x + docker stop -t 10 seafile + ) + fi + + bootstrap + + if [[ $existing != "" ]]; then + echo "Removing old container" + ( + set -x + docker rm seafile + ) + fi + + start + exit 0 } main() { diff --git a/templates/Dockerfile.template b/templates/Dockerfile.template index f420d84..9e33323 100644 --- a/templates/Dockerfile.template +++ b/templates/Dockerfile.template @@ -13,7 +13,6 @@ RUN cp -rp /app/scripts /scripts && \ cp /app/scripts/tmp/check_init_admin.py /opt/seafile/seafile-server-{{ seafile_version }}/check_init_admin.py && \ {%- endif %} {%- if https %} - cp /app/bootstrap/generated/seafile.nginx.conf /etc/nginx/sites-enabled/seafile.nginx.conf && \ cp /app/bootstrap/generated/letsencrypt.cron /etc/cron.d/letsencrypt.cron && \ {%- endif %} - echo "Done" + cp /app/bootstrap/generated/seafile.nginx.conf /etc/nginx/sites-enabled/seafile.nginx.conf