Merge branch 'cron-gc'

This commit is contained in:
Gerrit Gogel 2021-02-01 19:04:52 +01:00
commit fb27610cd9
6 changed files with 95 additions and 72 deletions

View file

@ -273,6 +273,21 @@ For OAuth the same network problem as with LDAP will occur, but here you will ne
caddy.rewrite: /accounts/login* /oauth/login/?
```
### Garbage Collection
Seafile has a block-based storage backend. This means that every file is associated to one or many blocks. If a file is permanently deleted from the trash bin, those blocks need to be cleared in order to free disk space. This process is called garbage collection.
You can manually run the garbage collection with `docker exec`, where `seafile-server` is the name of the container running *seafile-server*:
```
docker exec -it seafile-server /scripts/gc.sh
```
You can schedule a cron job for garbage collection, by adding the following environment variable to *seafile-server*:
```
- GC_CRON=0 6 * * SUN
```
This would run the garbage collection every sunday at 6AM.
### Docker Swarm
If you want to deploy this stack on a Docker Swarm with multiple nodes or if you want to run replicas of the frontend (clustering), there are several things you have to consider first.

View file

@ -14,6 +14,7 @@ FROM ubuntu:bionic
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y \
socat \
cron \
tzdata \
psmisc \
net-tools \
@ -34,9 +35,12 @@ COPY scripts /scripts
RUN chmod u+x /scripts/*
RUN mkdir -p /opt/seafile/logs &&\
ln -sf /dev/stdout /opt/seafile/logs/seafile.log &&\
ln -sf /dev/stdout /opt/seafile/logs/controller.log &&\
ln -sf /dev/stdout /opt/seafile/logs/ccnet.log
touch /opt/seafile/logs/common.log &&\
ln -sf /opt/seafile/logs/common.log /opt/seafile/logs/seafile.log &&\
ln -sf /opt/seafile/logs/common.log /opt/seafile/logs/controller.log &&\
ln -sf /opt/seafile/logs/common.log /opt/seafile/logs/ccnet.log &&\
ln -sf /opt/seafile/logs/common.log /opt/seafile/logs/gc.log &&\
ln -sf /opt/seafile/logs/common.log /opt/seafile/logs/seafdav.log
EXPOSE 8080 8082 8001

View file

@ -1,37 +1,22 @@
#!/bin/bash
set -e
# Before
source /scripts/utils.sh
SEAFILE_DIR=/opt/seafile/seafile-server-latest
if [[ $SEAFILE_SERVER != *"pro"* ]]; then
echo "Seafile CE: Stop Seafile to perform offline garbage collection."
$SEAFILE_DIR/seafile.sh stop
echo "Waiting for the server to shut down properly..."
sleep 5
echo "Seafile CE: Stop Seafile to perform offline garbage collection."
stop_socat
$SEAFILE_DIR/seafile.sh stop
echo "Waiting for the server to shut down properly..."
sleep 5
else
echo "Seafile Pro: Perform online garbage collection."
echo "Seafile Pro: Perform online garbage collection."
fi
# 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
$SEAFILE_DIR/seaf-gc.sh "$@"
if [[ $SEAFILE_SERVER != *"pro"* ]]; then
echo "Giving the server some time..."
sleep 3
$SEAFILE_DIR/seafile.sh start
echo "Seafile CE: Offline garbage collection completed. Starting Seafile."
sleep 3
$SEAFILE_DIR/seafile.sh start
start_socat
fi
exit $gc_exit_code

View file

@ -1,43 +1,10 @@
#!/bin/bash
function sigterm {
stop_socat
stop_server
exit 0
}
function start_server {
/scripts/create_data_links.sh
python3 /scripts/start.py
}
function stop_server {
echo "Stopping seafile server..."
/opt/seafile/seafile-server-latest/seafile.sh stop
}
function start_socat {
echo "Waiting for SeaRPC socket..."
while [ ! -S /opt/seafile/seafile-server-latest/runtime/seafile.sock ]; do
sleep 1
done
socat -d -d TCP-LISTEN:8001,fork,reuseaddr UNIX:/opt/seafile/seafile-server-latest/runtime/seafile.sock,forever
}
function stop_socat {
echo "Stopping socat..."
ps aux | grep '[s]ocat' | awk '{print $2}' | xargs kill -15 |& tee /dev/null
sleep 5
ps aux | grep '[s]ocat' | awk '{print $2}' | xargs kill -9 |& tee /dev/null
}
function keep_running {
while true; do
tail -f /dev/null & wait ${!}
done
}
source /scripts/utils.sh
trap 'sigterm' SIGTERM
gc_cron &
start_server &
start_socat &
logger &
keep_running

View file

@ -0,0 +1,50 @@
#!/bin/bash
function sigterm {
stop_socat
stop_server
exit 0
}
function start_server {
/scripts/create_data_links.sh
python3 /scripts/start.py
}
function stop_server {
echo "Stopping seafile server..."
/opt/seafile/seafile-server-latest/seafile.sh stop
}
function start_socat {
echo "Waiting for SeaRPC socket..."
while [ ! -S /opt/seafile/seafile-server-latest/runtime/seafile.sock ]; do
sleep 1
done
socat -d TCP-LISTEN:8001,fork,reuseaddr UNIX:/opt/seafile/seafile-server-latest/runtime/seafile.sock,forever
}
function stop_socat {
echo "Stopping socat..."
pkill -15 socat
sleep 5
pkill -9 socat
}
function gc_cron {
if [[ ! -z $GC_CRON ]]; then
echo "Scheduling garbage collection..."
(crontab -l ; echo "$GC_CRON /scripts/gc.sh >> /opt/seafile/logs/gc.log 2>&1") | crontab
service cron start
fi
}
function logger {
tail -f /opt/seafile/logs/common.log | tee /proc/1/fd/1
}
function keep_running {
while true; do
tail -f /dev/null & wait ${!}
done
}

View file

@ -13,22 +13,24 @@ function start_seahub {
function start_socat {
mkdir -p /opt/seafile/seafile-server-latest/runtime
while true; do
socat -d -d UNIX-LISTEN:/opt/seafile/seafile-server-latest/runtime/seafile.sock,fork TCP:seafile-server:8001,forever,keepalive,keepidle=10,keepintvl=10,keepcnt=2
while ! nc -z seafile-server 8001 2>/dev/null; do
sleep 1
done
echo "Starting socat..."
socat -d -d UNIX-LISTEN:/opt/seafile/seafile-server-latest/runtime/seafile.sock,fork TCP:seafile-server:8001,forever,keepalive,keepidle=10,keepintvl=10,keepcnt=2
}
function watch_server {
while true; do
if ! nc -z seafile-server 8001 2>/dev/null; then
if ! nc -z seafile-server 8080 2>/dev/null; then
echo "Seafile server is unreachable. Stopping seahub..."
pkill -f manage.py
while ! nc -z seafile-server 8001 2>/dev/null; do
while ! nc -z seafile-server 8080 2>/dev/null; do
sleep 1
done
start_seahub &
fi
sleep 1
sleep 2
done
}