mirror of
https://github.com/ggogel/seafile-containerized.git
synced 2024-11-16 09:01:38 +00:00
Add garbage collector command to launcher (#20)
* Add garbage collector command to launcher The seafile garbage collector can be started via the 'gc' command option of the launcher. This will stop the seafile-server inside the container, then run the 'seaf-gc.sh' script and redirect its output to '/var/log/gc.log'. Afterwards the whole container will be restarted. * Move garbage collector execution logic to scripts/gc.sh The file gc.sh stops the seafile server, starts the garbage collector and restarts the seafile server when the cleanup is finished. The output of the 'seaf-gc.sh' script is piped to the file '/var/log/gc.log' in append mode. * Add 'scripts/gc.sh' to watch_controller function in 'scripts/start.py' The 'start.py' script monitors the seafile-server in a 'watch_controller' function and terminates the container when the server crashed. However, during a garbage collector cleanup the server needs to be shut down and therefore it is necessary that the 'watch_controller' function only terminates the container if the server is offline and no cleanup is in progress. * Add the gc command info to README * Preseve the exit code of seaf-gc.sh * Fix the perm of scripts/gc.sh
This commit is contained in:
parent
5f89412d04
commit
702f5da610
|
@ -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.
|
||||
|
|
18
launcher
18
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 ;;
|
||||
|
|
30
scripts/gc.sh
Executable file
30
scripts/gc.sh
Executable file
|
@ -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
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue