Make debug logs and info logs more clear.

This commit is contained in:
Shuai Lin 2016-11-29 15:26:33 +08:00
parent 12412e733d
commit cc77e95d9f
5 changed files with 67 additions and 51 deletions

View file

@ -23,4 +23,11 @@ http {
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
server {
listen 80;
location / {
return 444;
}
}
}

View file

@ -32,13 +32,13 @@ version_stamp_file=$sharedir/seafile/seafile-data/current_version
cd $dockerdir
dlog() {
logdbg() {
if [[ $verbose == "true" ]]; then
show_progress "[debug] $1"
loginfo "[debug] $1"
fi
}
show_progress() {
loginfo() {
if [[ -t 1 ]]; then
>&2 printf "[$(date +'%Y-%m-%d %H:%M:%S')] \033[32m%s\033[m\n" "$1"
else
@ -139,9 +139,9 @@ bootstrap() {
fi
docker history $image >/dev/null 2>&1 || {
show_progress "Pulling Seafile server image $version, this may take a while."
loginfo "Pulling Seafile server image $version, this may take a while."
docker pull $image
show_progress "Seafile server image $version pulled. Now bootstrapping the server ..."
loginfo "Seafile server image $version pulled. Now bootstrapping the server ..."
}
# First initialize seafile server and letsencrypt
@ -151,15 +151,15 @@ bootstrap() {
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."
loginfo "Now building the local docker image."
docker build -f bootstrap/generated/Dockerfile -t local_seafile/server:latest . >/dev/null
show_progress "Image built."
loginfo "Image built."
}
start() {
existing=$(docker ps | awk '{ print $1, $(NF) }' | grep " seafile$" | awk '{ print $1 }' || true)
if [[ $existing != "" ]]; then
show_progress "Nothing to do, your container has already started!"
loginfo "Nothing to do, your container has already started!"
exit 0
fi
@ -169,7 +169,7 @@ start() {
set_existing_container
if [[ $existing != "" ]]; then
show_progress "starting up existing container"
loginfo "starting up existing container"
(
set -x
docker start seafile
@ -189,7 +189,7 @@ start() {
attach_on_run="-d"
fi
show_progress "Starting up new seafile server container"
loginfo "Starting up new seafile server container"
(
set -x
docker run $user_args $attach_on_run $restart_policy --name seafile -h seafile $envs $volumes $ports $local_image
@ -262,18 +262,18 @@ 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}"
logdbg "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"
show_progress "Please run './launcher rebuild' to upgrade"
loginfo "******* Major upgrade detected *******"
loginfo "You have $last_version, latest is $version"
loginfo "Please run './launcher rebuild' to upgrade"
exit 1
fi
}
check_upgrade() {
show_progress "Checking if there is major version upgrade"
loginfo "Checking if there is major version upgrade"
local last_version last_major_version current_major_version
last_version=$(cat $version_stamp_file)
@ -283,16 +283,16 @@ check_upgrade() {
if [[ $last_major_version == "$current_major_version" ]]; then
return
else
show_progress "********************************"
show_progress "Major upgrade detected: You have $last_version, latest is $version"
show_progress "********************************"
loginfo "********************************"
loginfo "Major upgrade detected: You have $last_version, latest is $version"
loginfo "********************************"
# use_manual_upgrade=true
if [[ $use_manual_upgrade == "true" ]]; then
show_progress "Now you can run './launcher manual-upgrade' to do manual upgrade."
loginfo "Now you can run './launcher manual-upgrade' to do manual upgrade."
exit 0
else
show_progress "Going to launch the docker container for manual upgrade"
loginfo "Going to launch the docker container for manual upgrade"
_launch_for_upgrade --auto
fi
fi
@ -319,7 +319,7 @@ _launch_for_upgrade() {
rebuild() {
if [[ "$(git symbolic-ref --short HEAD)" == "master" ]]; then
show_progress "Ensuring launcher is up to date"
loginfo "Ensuring launcher is up to date"
git remote update
@ -328,10 +328,10 @@ rebuild() {
BASE=$(git merge-base @ "@{u}")
if [[ $LOCAL = "$REMOTE" ]]; then
show_progress "Launcher is up-to-date"
loginfo "Launcher is up-to-date"
elif [[ $LOCAL = "$BASE" ]]; then
show_progress "Updating Launcher"
loginfo "Updating Launcher"
git pull || (echo 'failed to update' && exit 1)
for (( i=${#BASH_ARGV[@]}-1,j=0; i>=0,j<${#BASH_ARGV[@]}; i--,j++ ))
@ -341,9 +341,9 @@ rebuild() {
exec /bin/bash $0 "${args[@]}" # $@ is empty, because of shift at the beginning. Use BASH_ARGV instead.
elif [[ $REMOTE = "$BASE" ]]; then
show_progress "Your version of Launcher is ahead of origin"
loginfo "Your version of Launcher is ahead of origin"
else
show_progress "Launcher has diverged source, this is only expected in Dev mode"
loginfo "Launcher has diverged source, this is only expected in Dev mode"
fi
fi
@ -351,7 +351,7 @@ rebuild() {
set_existing_container
if [[ $existing != "" ]]; then
show_progress "Stopping old container"
loginfo "Stopping old container"
(
set -x
docker stop -t 10 seafile
@ -359,10 +359,10 @@ rebuild() {
fi
bootstrap
show_progress "Rebuilt successfully."
loginfo "Rebuilt successfully."
if [[ $existing != "" ]]; then
show_progress "Removing old container"
loginfo "Removing old container"
(
set -x
docker rm seafile
@ -373,7 +373,7 @@ rebuild() {
start
show_progress "Your seafile server is now running."
loginfo "Your seafile server is now running."
exit 0
}

View file

@ -16,7 +16,7 @@ import uuid
import time
from utils import (
call, get_conf, get_install_dir, show_progress,
call, get_conf, get_install_dir, loginfo,
get_script, render_template, get_seafile_version, eprint,
cert_has_valid_days, get_version_stamp_file, update_version_stamp,
wait_for_mysql, wait_for_nginx
@ -30,12 +30,13 @@ ssl_dir = '/shared/ssl'
generated_dir = '/bootstrap/generated'
def init_letsencrypt():
show_progress('Preparing for letsencrypt ...')
loginfo('Preparing for letsencrypt ...')
wait_for_nginx()
if not exists(ssl_dir):
os.mkdir(ssl_dir)
domain = get_conf('server.hostname')
context = {
'ssl_dir': ssl_dir,
'domain': domain,
@ -48,12 +49,12 @@ def init_letsencrypt():
ssl_crt = '/shared/ssl/{}.crt'.format(domain)
if exists(ssl_crt):
show_progress('Found existing cert file {}'.format(ssl_crt))
loginfo('Found existing cert file {}'.format(ssl_crt))
if cert_has_valid_days(ssl_crt, 30):
show_progress('Skip letsencrypt verification since we have a valid certificate')
loginfo('Skip letsencrypt verification since we have a valid certificate')
return
show_progress('Starting letsencrypt verification')
loginfo('Starting letsencrypt verification')
# Create a temporary nginx conf to start a server, which would accessed by letsencrypt
context = {
'https': False,
@ -62,8 +63,8 @@ def init_letsencrypt():
render_template('/templates/seafile.nginx.conf.template',
'/etc/nginx/sites-enabled/seafile.nginx.conf', context)
wait_for_nginx()
call('nginx -s reload')
time.sleep(2)
call('/scripts/ssl.sh {0} {1}'.format(ssl_dir, domain))
# if call('/scripts/ssl.sh {0} {1}'.format(ssl_dir, domain), check_call=False) != 0:
@ -90,7 +91,7 @@ def is_https():
return get_conf('server.letsencrypt', '').lower() == 'true'
def generate_local_dockerfile():
show_progress('Generating local Dockerfile ...')
loginfo('Generating local Dockerfile ...')
context = {
'seafile_version': seafile_version,
'https': is_https(),
@ -120,10 +121,10 @@ def init_seafile_server():
if exists(join(shared_seafiledir, 'seafile-data')):
if not exists(version_stamp_file):
update_version_stamp(version_stamp_file, os.environ['SEAFILE_VERSION'])
show_progress('Skip running setup-seafile-mysql.py because there is existing seafile-data folder.')
loginfo('Skip running setup-seafile-mysql.py because there is existing seafile-data folder.')
return
show_progress('Now running setup-seafile-mysql.py in auto mode.')
loginfo('Now running setup-seafile-mysql.py in auto mode.')
env = {
'SERVER_NAME': 'seafile',
'SERVER_IP': get_conf('server.hostname'),
@ -155,8 +156,8 @@ 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'])
loginfo('Updating version stamp')
update_version_stamp(os.environ['SEAFILE_VERSION'])
def main():
args = parse_args()
@ -177,7 +178,7 @@ def main():
wait_for_mysql()
init_seafile_server()
show_progress('Generated local config.')
loginfo('Generated local config.')
if __name__ == '__main__':

View file

@ -18,7 +18,7 @@ import time
from utils import (
call, get_install_dir, get_script, get_command_output, replace_file_pattern,
read_version_stamp, wait_for_mysql, update_version_stamp, show_progress
read_version_stamp, wait_for_mysql, update_version_stamp, loginfo
)
installdir = get_install_dir()
@ -62,7 +62,7 @@ def check_upgrade():
scripts_to_run = collect_upgrade_scripts(from_version=last_version, to_version=current_version)
for script in scripts_to_run:
show_progress('Running scripts {}'.format(script))
loginfo('Running scripts {}'.format(script))
new_version = parse_upgrade_script_version(script)[1] + '.0'
replace_file_pattern(script, 'read dummy', '')

View file

@ -58,8 +58,8 @@ def call(*a, **kw):
for arg in reduct_args:
value = _find_flag(args, arg)
toprint = toprint.replace(value, '{}**reducted**'.format(value[:3]))
eprint('calling: ', green(toprint))
eprint('cwd: ', green(cwd))
logdbg('calling: ' + green(toprint))
logdbg('cwd: ' + green(cwd))
kw.setdefault('shell', True)
if not dry_run:
if check_call:
@ -238,7 +238,14 @@ def render_template(template, target, context):
with open(target, 'w') as fp:
fp.write(content)
def show_progress(msg):
def logdbg(msg):
if DEBUG_ENABLED:
msg = '[debug] ' + msg
loginfo(msg)
DEBUG_ENABLED = os.environ.get('SEAFILE_DOCKER_VERBOSE', '').lower() in ('true', '1', 'yes')
def loginfo(msg):
msg = '[{}] {}'.format(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), green(msg))
eprint(msg)
@ -263,16 +270,17 @@ def update_version_stamp(version, fn=get_version_stamp_file()):
def wait_for_mysql():
while not exists('/var/run/mysqld/mysqld.sock'):
print('waiting for mysql server to be ready')
logdbg('waiting for mysql server to be ready')
time.sleep(2)
print('mysql server is ready')
logdbg('mysql server is ready')
def wait_for_nginx():
while True:
print('waiting for nginx server to be ready')
logdbg('waiting for nginx server to be ready')
output = get_command_output('netstat -nltp')
if ':80 ' in output:
print('nginx is ready')
logdbg(output)
logdbg('nginx is ready')
return
time.sleep(2)