diff --git a/Dockerfile.bash b/Dockerfile.bash index 401cde5..a6b37bb 100644 --- a/Dockerfile.bash +++ b/Dockerfile.bash @@ -50,7 +50,7 @@ RUN mkdir -p /etc/apt/sources.list.d/ ;\ useradd -m -u $UID -g $GID -o -s /bin/bash $UNAME # 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 ENTRYPOINT ["/bin/bash", "/entrypoint.sh"] diff --git a/Dockerfile.cron b/Dockerfile.cron index 3cd88ab..cbdff82 100644 --- a/Dockerfile.cron +++ b/Dockerfile.cron @@ -49,13 +49,13 @@ RUN mkdir -p /etc/apt/sources.list.d/ ;\ /import-seafile-apt-key.sh ;\ mkdir /volume/ ;\ 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 ;\ groupadd -g $GID -o $UNAME ;\ useradd -m -u $UID -g $GID -o -s /bin/bash $UNAME # 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 ENTRYPOINT ["/bin/bash", "/entrypoint.sh"] diff --git a/Dockerfile.supervisord b/Dockerfile.supervisord index 81dd58e..1bafdb2 100644 --- a/Dockerfile.supervisord +++ b/Dockerfile.supervisord @@ -52,7 +52,7 @@ RUN mkdir -p /etc/apt/sources.list.d/ ;\ useradd -m -u $UID -g $GID -o -s /bin/bash $UNAME # 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 ENTRYPOINT ["/bin/bash", "/entrypoint.sh"] diff --git a/README.md b/README.md index 7851453..ed8ac59 100644 --- a/README.md +++ b/README.md @@ -44,12 +44,13 @@ Docker Seafile Client allow you to sync a Seafile library within a container. # 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 *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. -*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. +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 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 You would have to share the path `/volume/` to other containers, with the following approaches: ### Docker CLI diff --git a/assets/docker-bash-entrypoint.sh b/assets/docker-bash-entrypoint.sh index c446e0f..c2cf920 100644 --- a/assets/docker-bash-entrypoint.sh +++ b/assets/docker-bash-entrypoint.sh @@ -39,7 +39,7 @@ if [ "$GID" != "1000" ]; then fi # 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 /volume diff --git a/assets/docker-cron-entrypoint.sh b/assets/docker-cron-entrypoint.sh index 39ea374..901e7d4 100644 --- a/assets/docker-cron-entrypoint.sh +++ b/assets/docker-cron-entrypoint.sh @@ -39,7 +39,7 @@ if [ "$GID" != "1000" ]; then fi # 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 -R /volume diff --git a/assets/docker-supervisord-entrypoint.sh b/assets/docker-supervisord-entrypoint.sh index 23906f8..0fef05e 100644 --- a/assets/docker-supervisord-entrypoint.sh +++ b/assets/docker-supervisord-entrypoint.sh @@ -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. if [ "$UID" != "1000" ]; then usermod -u $UID $UNAME - # What if the $UID already exists ? + # TODO: What if the $UID already exists ? fi # Change the group, if the $GID changed. @@ -40,7 +40,7 @@ fi # Set the files ownership. 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 /volume diff --git a/assets/infinite-seaf-cli-start.sh b/assets/infinite-seaf-cli-start.sh deleted file mode 100755 index 5aadbcf..0000000 --- a/assets/infinite-seaf-cli-start.sh +++ /dev/null @@ -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 . - -/bin/sleep 10 -while true; do - /usr/bin/seaf-cli stop - /usr/bin/seaf-cli start - /bin/sleep 1200 -done \ No newline at end of file diff --git a/assets/seafile-bash-entrypoint.sh b/assets/seafile-bash-entrypoint.sh index 52aa07d..a029c5b 100644 --- a/assets/seafile-bash-entrypoint.sh +++ b/assets/seafile-bash-entrypoint.sh @@ -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 # Run the infinite Seafile restart. -source ~/infinite-seaf-cli-start.sh +source ~/seafile-healthcheck.sh diff --git a/assets/seafile-cron-entrypoint.sh b/assets/seafile-cron-entrypoint.sh index 7716ba7..2a2baec 100644 --- a/assets/seafile-cron-entrypoint.sh +++ b/assets/seafile-cron-entrypoint.sh @@ -22,7 +22,6 @@ seafile_sock=~/.seafile/seafile-data/seafile.sock # Prepare the directories. mkdir ~/.seafile -mkdir ~/.supervisord # Safely initialise the Seafile client. /usr/bin/seaf-cli init -d ~/.seafile diff --git a/assets/seafile-cron-healthcheck.sh b/assets/seafile-cron-healthcheck.sh new file mode 100755 index 0000000..2f41124 --- /dev/null +++ b/assets/seafile-cron-healthcheck.sh @@ -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 . + +# `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 diff --git a/assets/seafile-healthcheck.sh b/assets/seafile-healthcheck.sh new file mode 100755 index 0000000..16f60d4 --- /dev/null +++ b/assets/seafile-healthcheck.sh @@ -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 . + +# `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 \ No newline at end of file diff --git a/assets/supervisord.conf b/assets/supervisord.conf index 560c374..2139015 100644 --- a/assets/supervisord.conf +++ b/assets/supervisord.conf @@ -24,7 +24,7 @@ file=~/.seafile/seafile-data/seafile.sock # Manage the infinite `seaf-cli start`. [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 numprocs=1 autostart=true diff --git a/utils/publish/update-docker-hub-full-description.sh b/utils/publish/update-docker-hub-full-description.sh index 50908df..670eb53 100644 --- a/utils/publish/update-docker-hub-full-description.sh +++ b/utils/publish/update-docker-hub-full-description.sh @@ -1,8 +1,27 @@ #!/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 . + # Based upon https://gist.github.com/jlhawn/8f218e7c0b14c941c41f # 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. apk add curl jq