Merge feature--infinite-seafile-restart-into-healthchecks into staging

This commit is contained in:
flow.gunso
2019-04-25 16:42:23 +02:00
14 changed files with 122 additions and 38 deletions

View File

@@ -50,7 +50,7 @@ RUN mkdir -p /etc/apt/sources.list.d/ ;\
useradd -m -u $UID -g $GID -o -s /bin/bash $UNAME useradd -m -u $UID -g $GID -o -s /bin/bash $UNAME
# Copy over the required files for Seafile/SupervisorD. # Copy over the required files for Seafile/SupervisorD.
COPY assets/supervisord.conf assets/infinite-seaf-cli-start.sh /home/seafuser/ COPY assets/seafile-healthcheck.sh /home/seafuser/
COPY assets/seafile-bash-entrypoint.sh /home/seafuser/entrypoint.sh COPY assets/seafile-bash-entrypoint.sh /home/seafuser/entrypoint.sh
ENTRYPOINT ["/bin/bash", "/entrypoint.sh"] ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]

View File

@@ -49,13 +49,13 @@ RUN mkdir -p /etc/apt/sources.list.d/ ;\
/import-seafile-apt-key.sh ;\ /import-seafile-apt-key.sh ;\
mkdir /volume/ ;\ mkdir /volume/ ;\
echo "seafuser" > /etc/cron.allow ;\ echo "seafuser" > /etc/cron.allow ;\
echo "*/20 * * * * /bin/bash /home/seafuser/infinite-seaf-cli-start.sh" \ echo "*/20 * * * * /bin/bash /home/seafuser/seafile-healthcheck.sh" \
> /var/spool/cron/crontabs/seafuser ;\ > /var/spool/cron/crontabs/seafuser ;\
groupadd -g $GID -o $UNAME ;\ groupadd -g $GID -o $UNAME ;\
useradd -m -u $UID -g $GID -o -s /bin/bash $UNAME useradd -m -u $UID -g $GID -o -s /bin/bash $UNAME
# Copy over the required files for Seafile/SupervisorD. # Copy over the required files for Seafile/SupervisorD.
COPY assets/infinite-seaf-cli-start.sh /home/seafuser/ COPY assets/seafile-cron-healthcheck.sh /home/seafuser/seafile-healthcheck.sh
COPY assets/seafile-cron-entrypoint.sh /home/seafuser/entrypoint.sh COPY assets/seafile-cron-entrypoint.sh /home/seafuser/entrypoint.sh
ENTRYPOINT ["/bin/bash", "/entrypoint.sh"] ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]

View File

@@ -52,7 +52,7 @@ RUN mkdir -p /etc/apt/sources.list.d/ ;\
useradd -m -u $UID -g $GID -o -s /bin/bash $UNAME useradd -m -u $UID -g $GID -o -s /bin/bash $UNAME
# Copy over the required files for Seafile/SupervisorD. # Copy over the required files for Seafile/SupervisorD.
COPY assets/supervisord.conf assets/infinite-seaf-cli-start.sh /home/seafuser/ COPY assets/supervisord.conf assets/seafile-healthcheck.sh /home/seafuser/
COPY assets/seafile-supervisord-entrypoint.sh /home/seafuser/entrypoint.sh COPY assets/seafile-supervisord-entrypoint.sh /home/seafuser/entrypoint.sh
ENTRYPOINT ["/bin/bash", "/entrypoint.sh"] ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]

View File

@@ -44,12 +44,13 @@ Docker Seafile Client allow you to sync a Seafile library within a container.
# Usage # Usage
The *Seafile* daemon is running from `/.seafile/` and `~/.ccnet`. The *Seafile* daemon is running as the user `seafuser` from it's directories `~/.seafile/` and `~/.ccnet`.
The library is synced at `/volume/`. The library is synced at `/volume/`.
The *Seafile* daemon is managed with *supervisord* since it can't run as a foreground process. The *Seafile* daemon is managed with *supervisord* since it can't run as a foreground process.
The *supervisord* is running from `/.supervisord/`, the `supervisord.conf`, `supervisord.log` and `supervisord.pid` can be found there. The *supervisord* is running from `~/.supervisord/`, the `supervisord.conf`, `supervisord.log` and `supervisord.pid` can be found there.
*supervisord* also manage a shell script, `/infinite-seaf-cli-start.sh` which run `seaf-cli start` every hour: the synchronisation might not work properly if `seaf-cli start` is not run from times to times, for an unresolved reason. *supervisord* also manage a shell script, `~/infinite-seaf-cli-start.sh` which stop then start the Seafile daemon every 20 minutes: the synchronisation might not work properly if the Seafile daemon is not restarted from times to times, for an unresolved reason.
## Examples ## Examples
You would have to share the path `/volume/` to other containers, with the following approaches: You would have to share the path `/volume/` to other containers, with the following approaches:
### Docker CLI ### Docker CLI

View File

@@ -39,7 +39,7 @@ if [ "$GID" != "1000" ]; then
fi fi
# Set the files ownership. # Set the files ownership.
chown $UID.$GID -R /home/seafuser/infinite-seaf-cli-start.sh chown $UID.$GID -R /home/seafuser/seafile-healthcheck.sh
chown $UID.$GID -R /home/seafuser/entrypoint.sh chown $UID.$GID -R /home/seafuser/entrypoint.sh
chown $UID.$GID -R /volume chown $UID.$GID -R /volume

View File

@@ -39,7 +39,7 @@ if [ "$GID" != "1000" ]; then
fi fi
# Set the files ownership. # Set the files ownership.
chown $UID.$GID /home/seafuser/infinite-seaf-cli-start.sh chown $UID.$GID /home/seafuser/seafile-healthcheck.sh
chown $UID.$GID /home/seafuser/entrypoint.sh chown $UID.$GID /home/seafuser/entrypoint.sh
chown $UID.$GID -R /volume chown $UID.$GID -R /volume

View File

@@ -25,7 +25,7 @@ if [ -z $SEAF_LIBRARY_UUID ]; then echo "The \$SEAF_LIBRARY_UUID was not defined
# Update the user ID, if the $UID changed. # Update the user ID, if the $UID changed.
if [ "$UID" != "1000" ]; then if [ "$UID" != "1000" ]; then
usermod -u $UID $UNAME usermod -u $UID $UNAME
# What if the $UID already exists ? # TODO: What if the $UID already exists ?
fi fi
# Change the group, if the $GID changed. # Change the group, if the $GID changed.
@@ -40,7 +40,7 @@ fi
# Set the files ownership. # Set the files ownership.
chown $UID.$GID -R /home/seafuser/supervisord.conf chown $UID.$GID -R /home/seafuser/supervisord.conf
chown $UID.$GID -R /home/seafuser/infinite-seaf-cli-start.sh chown $UID.$GID -R /home/seafuser/seafile-healthcheck.sh
chown $UID.$GID -R /home/seafuser/entrypoint.sh chown $UID.$GID -R /home/seafuser/entrypoint.sh
chown $UID.$GID -R /volume chown $UID.$GID -R /volume

View File

@@ -1,24 +0,0 @@
#!/bin/bash
# Docker Seafile client, help you mount a Seafile library as a volume.
# Copyright (C) 2019, flow.gunso@gmail.com
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
/bin/sleep 10
while true; do
/usr/bin/seaf-cli stop
/usr/bin/seaf-cli start
/bin/sleep 1200
done

View File

@@ -35,4 +35,4 @@ while [ ! -S $seafile_sock ]; do sleep 1; done
/usr/bin/seaf-cli sync -u $SEAF_USERNAME -p $SEAF_PASSWORD -s $SEAF_SERVER_URL -l $SEAF_LIBRARY_UUID -d /volume /usr/bin/seaf-cli sync -u $SEAF_USERNAME -p $SEAF_PASSWORD -s $SEAF_SERVER_URL -l $SEAF_LIBRARY_UUID -d /volume
# Run the infinite Seafile restart. # Run the infinite Seafile restart.
source ~/infinite-seaf-cli-start.sh source ~/seafile-healthcheck.sh

View File

@@ -22,7 +22,6 @@ seafile_sock=~/.seafile/seafile-data/seafile.sock
# Prepare the directories. # Prepare the directories.
mkdir ~/.seafile mkdir ~/.seafile
mkdir ~/.supervisord
# Safely initialise the Seafile client. # Safely initialise the Seafile client.
/usr/bin/seaf-cli init -d ~/.seafile /usr/bin/seaf-cli init -d ~/.seafile

View File

@@ -0,0 +1,42 @@
#!/bin/bash
# Docker Seafile client, help you mount a Seafile library as a volume.
# Copyright (C) 2019, flow.gunso@gmail.com
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# `seaf-cli status` output csv-like information with tabulates as separators and columns named in comment lines.
# The Seafile client should not be restarted while some statuses are occuring, such as "downloading" or "committing".
#
# This script grabs the output while ignoring the comments to iterate over the informations set to their columns,
# then it compares the statuses, when not empty, to the ones that do not require a restart. Finally either restart or don't.
seaf=/usr/bin/seaf-cli
dont_restart_on=("downloading" "committing" "waiting for sync")
restart=true
while IFS=$'\t' read -r name status progress; do
if [ $status ]; then
for dont_restart_on_status in "${dont_restart_on[@]}"; do
if [ "$status" == "$dont_restart_on_status" ]; then
restart=false; break; break
fi
done
fi
done < <($seaf status | grep -v "^#")
if $restart; then
$seaf stop
$seaf start
fi

47
assets/seafile-healthcheck.sh Executable file
View File

@@ -0,0 +1,47 @@
#!/bin/bash
# Docker Seafile client, help you mount a Seafile library as a volume.
# Copyright (C) 2019, flow.gunso@gmail.com
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# `seaf-cli status` output csv-like information with tabulates as separators and columns named in comment lines.
# The Seafile client should not be restarted while some statuses are occuring, such as "downloading" or "committing".
#
# This script grabs the output while ignoring the comments to iterate over the informations set to their columns,
# then it compares the statuses, when not empty, to the ones that do not require a restart. Finally either restart or don't.
seaf=/usr/bin/seaf-cli
dont_restart_on=("downloading" "committing" "waiting for sync")
restart=true
sleep 10s
while true; do
while IFS=$'\t' read -r name status progress; do
if [ $status ]; then
for dont_restart_on_status in "${dont_restart_on[@]}"; do
if [ "$status" == "$dont_restart_on_status" ]; then
restart=false; break; break
fi
done
fi
done < <($seaf status | grep -v "^#")
if $restart; then
$seaf stop
$seaf start
fi
sleep 10m
done

View File

@@ -24,7 +24,7 @@ file=~/.seafile/seafile-data/seafile.sock
# Manage the infinite `seaf-cli start`. # Manage the infinite `seaf-cli start`.
[program:seaf-cli-start-loop] [program:seaf-cli-start-loop]
command=/bin/bash /home/seafuser/infinite-seaf-cli-start.sh command=/bin/bash /home/seafuser/seafile-healthcheck.sh
process_name=%(program_name)s process_name=%(program_name)s
numprocs=1 numprocs=1
autostart=true autostart=true

View File

@@ -1,8 +1,27 @@
#!/bin/bash #!/bin/bash
# Docker Seafile client, help you mount a Seafile library as a volume.
# Copyright (C) 2019, flow.gunso@gmail.com
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# Based upon https://gist.github.com/jlhawn/8f218e7c0b14c941c41f # Based upon https://gist.github.com/jlhawn/8f218e7c0b14c941c41f
# and https://github.com/moikot/golang-dep/blob/master/.travis/push.sh # and https://github.com/moikot/golang-dep/blob/master/.travis/push.sh
# This action can only be done with the actual owner of the repository,
# unless you can extend the collaborator's permissions but as far as I know, you can't.
# Install required system packages. # Install required system packages.
apk add curl jq apk add curl jq