diff --git a/README.md b/README.md index f652a90..b2677f1 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,7 @@ Commands: enter: Use docker exec to enter a container logs: Docker logs for container rebuild: Rebuild a container (destroy old, bootstrap, start new) + gc: Start the seafile garbage collector (stops seafile, starts gc, restarts seafile) ``` If the environment variable "SUPERVISED" is set to true, the container won't be detached, allowing a process monitoring tool to manage the restart behaviour of the container. diff --git a/launcher b/launcher index 4939204..712a1c3 100755 --- a/launcher +++ b/launcher @@ -11,6 +11,7 @@ usage () { echo " logs: View the Docker container logs" echo " bootstrap: Bootstrap the container based on a template" echo " rebuild: Rebuild the container (destroy old, bootstrap, start new)" + echo " gc: Start the seafile garbage collector (stops seafile, starts gc, restarts seafile)" echo echo "Options:" echo " --skip-prereqs Don't check launcher prerequisites" @@ -224,6 +225,21 @@ restart() { start } +gc() { + ensure_container_running + ( + loginfo "Stop seafile and start the garbage collector" + set +e +x + docker exec -it seafile /scripts/gc.sh + gc_error=$? + if [[ $gc_error -eq 0 ]]; then + loginfo "Garbage collector finished!" + else + err_and_quit "Garbage collector exited with code $gc_error" + fi + ) +} + check_prereqs() { if [[ $SKIP_PREREQS == "true" ]]; then return 0 @@ -391,7 +407,7 @@ main() { while [[ $# -gt 0 ]] do case "$1" in - bootstrap|start|stop|restart|enter|destroy|logs|rebuild|manual-upgrade) + bootstrap|start|stop|restart|enter|destroy|logs|rebuild|manual-upgrade|gc) action=${1//-/_} ; shift 1 ;; -h|--help) ( usage ; exit 1) ; shift 1 ;; -v|--verbose) verbose=true ; shift 1 ;; diff --git a/scripts/gc.sh b/scripts/gc.sh new file mode 100755 index 0000000..b7049c6 --- /dev/null +++ b/scripts/gc.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +set -e + +# Before +SEAFILE_DIR=/opt/seafile/seafile-server-latest + +$SEAFILE_DIR/seafile.sh stop + +echo "Waiting for the server to shut down properly..." +sleep 5 + +# Do it +( + set +e + $SEAFILE_DIR/seaf-gc.sh | tee -a /var/log/gc.log + # We want to presevent the exit code of seaf-gc.sh + exit "${PIPESTATUS[0]}" +) + +gc_exit_code=$? + +# After + +echo "Giving the server some time..." +sleep 3 + +$SEAFILE_DIR/seafile.sh start + +exit $gc_exit_code diff --git a/scripts/start.py b/scripts/start.py index 913638f..91897c7 100755 --- a/scripts/start.py +++ b/scripts/start.py @@ -25,8 +25,9 @@ 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: + controller_pid = get_command_output('ps aux | grep seafile-controller | grep -v grep || true').strip() + garbage_collector_pid = get_command_output('ps aux | grep /scripts/gc.sh | grep -v grep || true').strip() + if not controller_pid and not garbage_collector_pid: retry += 1 else: retry = 0