From c513f2ab95ab3f2b99bad8d83dea167303f2f5a5 Mon Sep 17 00:00:00 2001 From: shim_ <> Date: Sun, 11 Nov 2018 18:32:35 +0100 Subject: [PATCH 01/14] no_media version --- .drone.yml | 1 + nginx/seafile/media.conf | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.drone.yml b/.drone.yml index 5780678..c72e612 100644 --- a/.drone.yml +++ b/.drone.yml @@ -7,6 +7,7 @@ pipeline: docker: image: plugins/docker repo: repo.shimun.net/shimun/seafile + tag: no_media registry: repo.shimun.net storage_path: /drone/.docker secrets: ["docker_username", "docker_password"] diff --git a/nginx/seafile/media.conf b/nginx/seafile/media.conf index 6548f00..e69de29 100644 --- a/nginx/seafile/media.conf +++ b/nginx/seafile/media.conf @@ -1,3 +0,0 @@ -location /media { - root /opt/seafile/seafile-server-latest/seahub; -} From 4ebc0bdf821825975706d6343405c937d5f9e305 Mon Sep 17 00:00:00 2001 From: shimunn <> Date: Fri, 19 Apr 2019 18:52:36 +0200 Subject: [PATCH 02/14] [CI SKIP] proper init --- Dockerfile | 28 ++++++++++--- riffol.conf | 102 +++++++++++++++++++++++++++++++++++++++++++++++ scripts/setup.sh | 42 +++++++++++++++++++ 3 files changed, 167 insertions(+), 5 deletions(-) create mode 100644 riffol.conf create mode 100644 scripts/setup.sh diff --git a/Dockerfile b/Dockerfile index 2bf2662..4c121f7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,7 @@ +FROM rust:1.34 AS riffol_build + +RUN cargo install --git https:/github.com/riboseinc/riffol + FROM nginx:mainline VOLUME /opt/seafile @@ -11,18 +15,32 @@ COPY requirements.txt /tmp/requirements.txt RUN apt update && apt install locales -y && apt install -y --no-install-recommends procps openssl python2.7 sqlite3 python-mysqldb python-pil curl libjansson4 libfuse2 python-pip python-pip-whl python-setuptools \ && pip install -r /tmp/requirements.txt && apt remove -y python-pip \ && rm -rf /var/lib/apt/lists/* /tmp/requirements.txt + +#ENV RIFFOL_VERSION libc-2.24 +#ENV RIFFOL_HASH e6aea0a91abe74dc0892b0814a0485f16ce8b738b4672b4980b15a398c013e974d5d1b6c27eed69899196cc21014e407f7ff74ee5636a8690ebd639fe0ca5abb +#RUN curl -L https://github.com/riboseinc/riffol/releases/download/0.1.0/riffol-$RIFFOL_VERSION.tar.gz -o /tmp/riffol-$RIFFOL_VERSION.tar.gz && \ +# echo "$RIFFOL_HASH /tmp/riffol-$RIFFOL_VERSION.tar.gz" | sha512sum --check && \ +# tar -xvzf /tmp/riffol-$RIFFOL_VERSION.tar.gz -C /usr/sbin/ && \ +# rm /tmp/riffol-$RIFFOL_VERSION.tar.gz + +COPY --from=riffol_build /usr/local/cargo/bin/riffol /usr/sbin/ + +RUN ln -s /opt/seafile/seafile-server-latest/seafile.sh /usr/bin/seafile && \ + ln -s /opt/seafile/seafile-server-latest/seahub.sh /usr/bin/seahub && \ + mkdir -p /var/run/seafile && \ + ln -s /opt/seafile/pids /var/run/seafile + +COPY riffol.conf /etc/riffol.conf COPY conf /opt/seafile/conf COPY conf /etc/seafile COPY nginx /etc/nginx COPY scripts/upgrade.py /usr/local/sbin/upgrade -COPY scripts/seafile-server.sh /sbin/seafile-server +COPY scripts/setup.sh /usr/bin/setup RUN ulimit -n 30000 && mkdir -p $SEAF/pids && \ - chmod +x /usr/local/sbin/upgrade /sbin/seafile-server + chmod +x /usr/local/sbin/upgrade /usr/bin/setup ENV SEAF_UPGRADE_INTERVAL=3 -ENTRYPOINT ["/sbin/seafile-server"] -#Defaults to run-upgrade options include: run, run-upgrade, upgrade, stop, stop-upgrade -CMD ["run-upgrade"] +ENTRYPOINT ["/usr/sbin/riffol", "-f", "/etc/riffol.conf"] diff --git a/riffol.conf b/riffol.conf new file mode 100644 index 0000000..443ac20 --- /dev/null +++ b/riffol.conf @@ -0,0 +1,102 @@ +init seafile { + application_groups [ "applicationgroup.seafile" ] +} + +application_group seafile { + applications [ + "application.setup" + "application.seahub" + "application.seafile" + "application.nginx" +] + +application "setup" { + mode oneshot + start [ /usr/bin/setup ] + pidfile /var/run/setup.pid + dir /opt/seafile + env { + pass SEAF_VERSION SEAF_VERSION + pass SEAF_UPGRADE_INTERVAL SEAF_UPGRADE_INTERVAL + } + stdout file [ /dev/stdout ] + stderr file [ /dev/stderr ] + uid 0 + gid 0 +} + +application "nginx" { + mode oneshot + start [ /usr/sbin/nginx ] + requires [ setup seahub ] + pidfile /var/run/nginx/nginx.pid + dir /opt/seafile + stdout file [ /dev/log ] + stderr file [ /dev/stderr ] + uid 0 + gid 0 + healthchecks [ + "healthcheck.http" + ] + healthcheckfail restart +} + +application "seafile" { + mode forking + requires [ setup ] + start [ /usr/bin/seafile, start ] + stop [ /usr/bin/seafile, stop ] + pidfile /var/run/seafile/seafile.pid + dir /opt/seafile + stdout file [ /dev/stdout ] + stderr file [ /dev/stderr ] + uid 0 + gid 0 + healthchecks [ + "healthcheck.server" + ] + healthcheckfail restart +} + +application seahub" { + mode forking + requires [ setup ] + start [ /usr/bin/seahub, start, 8000 ] + stop [ /usr/bin/seahub, stop ] + pidfile /var/run/seafile/seahub.pid + dir /opt/seafile + stdout file [ /dev/stdout ] + stderr file [ /dev/stderr ] + uid 0 + gid 0 + healthchecks [ + "healthcheck.hub" + ] + healthcheckfail restart +} + + +healthcheck http { + checks [ + "http://127.0.0.1:80" + ] + interval 15 + timeout 20 +} + +healthcheck hub { + checks [ + "http://127.0.0.1:8000" + "tcp://127.0.0.1:8080", + ] + interval 15 + timeout 60 +} + +healthcheck server { + checks [ + "http://127.0.0.1:8082" + ] + interval 15 + timeout 15 +} diff --git a/scripts/setup.sh b/scripts/setup.sh new file mode 100644 index 0000000..b97c30d --- /dev/null +++ b/scripts/setup.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +LATEST=$SEAF/seafile-server-latest + +function ext_url { + echo "${SEAF_URL:-http://$(hostname)}/seafhttp" +} +function patch_seahub_conf { + KEY="FILE_SERVER_ROOT" + ENTRY="$KEY = '$(ext_url)'" + CONF="$SEAF/conf/seahub_settings.py" + grep "$KEY" -i "$CONF" + if [ $? -eq 1 ]; then + echo "Patched seahub_settings.py: set $ENTRY" + echo -e "\n$ENTRY" >> "$CONF" + fi +} +function last_update { + if [ -e "$LATEST/install_date" ]; then + date -d $(cat "$LATEST/install_date") "+%s" + else + echo 0 + fi +} + +### Setup ### + +if [ ! -e "$LATEST" ]; then + (>&2 echo This appears to be the fist run, installing..) + mkdir -p $SEAF/conf + cp /etc/seafile/* $SEAF/conf/* -rf + /usr/local/sbin/upgrade main + exit $? +else + LAST_UPGRADE=$(last_update) + SINCE_UPGRADE=$(((($(date "+%s") - $LAST_UPGRADE))/(60*60*24))) + if [ $LAST_UPGRADE -gt 0 ] && [ "0$SEAF_UPGRADE_INTERVAL" -gt 0 ] && [ $SINCE_UPGRADE -gt "0$SEAF_UPGRADE_INTERVAL" ]; then + echo "It's been $SINCE_UPGRADE days since the last Upgrade\nPERFORMING UPGRADE NOW\nSet SEAF_UPGRADE_INTERVAL=0 disable automatic updates" + /usr/local/sbin/upgrade main + fi + patch_seahub_conf +fi From 06f0703a897c1528fe3c86adb6ffa831bcd1367a Mon Sep 17 00:00:00 2001 From: shimunn <> Date: Fri, 19 Apr 2019 20:45:10 +0200 Subject: [PATCH 03/14] fixed format error [CI SKIP] --- riffol.conf | 159 ++++++++++++++++++++++++++-------------------------- 1 file changed, 79 insertions(+), 80 deletions(-) diff --git a/riffol.conf b/riffol.conf index 443ac20..415c4cf 100644 --- a/riffol.conf +++ b/riffol.conf @@ -1,102 +1,101 @@ init seafile { - application_groups [ "applicationgroup.seafile" ] + application_groups [seafile] } application_group seafile { applications [ - "application.setup" - "application.seahub" - "application.seafile" - "application.nginx" -] - -application "setup" { - mode oneshot - start [ /usr/bin/setup ] - pidfile /var/run/setup.pid - dir /opt/seafile - env { - pass SEAF_VERSION SEAF_VERSION - pass SEAF_UPGRADE_INTERVAL SEAF_UPGRADE_INTERVAL - } - stdout file [ /dev/stdout ] - stderr file [ /dev/stderr ] - uid 0 - gid 0 + setup + seafile + seahub + nginx + ] } -application "nginx" { - mode oneshot - start [ /usr/sbin/nginx ] - requires [ setup seahub ] - pidfile /var/run/nginx/nginx.pid - dir /opt/seafile - stdout file [ /dev/log ] - stderr file [ /dev/stderr ] - uid 0 - gid 0 - healthchecks [ - "healthcheck.http" - ] - healthcheckfail restart +application setup { + mode oneshot + start [ /usr/bin/setup ] + dir /opt/seafile + env { + pass SEAF_VERSION SEAF_VERSION + pass SEAF_UPGRADE_INTERVAL SEAF_UPGRADE_INTERVAL + } + stdout file [ /dev/stdout ] + stderr file [ /dev/stderr ] + uid 0 + gid 0 } -application "seafile" { - mode forking - requires [ setup ] - start [ /usr/bin/seafile, start ] - stop [ /usr/bin/seafile, stop ] - pidfile /var/run/seafile/seafile.pid - dir /opt/seafile - stdout file [ /dev/stdout ] - stderr file [ /dev/stderr ] - uid 0 - gid 0 - healthchecks [ - "healthcheck.server" - ] - healthcheckfail restart +application seafile { + mode forking + requires [ setup ] + start [ /usr/bin/seafile, start ] + stop [ /usr/bin/seafile, stop ] + pidfile /var/run/seafile/seafile.pid + dir /opt/seafile + stdout file [ /dev/stdout ] + stderr file [ /dev/stderr ] + uid 0 + gid 0 + healthchecks [ + server + ] + healthcheckfail restart } -application seahub" { - mode forking - requires [ setup ] - start [ /usr/bin/seahub, start, 8000 ] - stop [ /usr/bin/seahub, stop ] - pidfile /var/run/seafile/seahub.pid - dir /opt/seafile - stdout file [ /dev/stdout ] - stderr file [ /dev/stderr ] - uid 0 - gid 0 - healthchecks [ - "healthcheck.hub" - ] - healthcheckfail restart +application seahub { + mode forking + requires [ setup ] + start [ /usr/bin/seahub, start, 8000 ] + stop [ /usr/bin/seahub, stop ] + pidfile /var/run/seafile/seahub.pid + dir /opt/seafile + stdout file [ /dev/stdout ] + stderr file [ /dev/stderr ] + uid 0 + gid 0 + healthchecks [ + hub + ] + healthcheckfail restart } +application nginx { + mode oneshot + start [ /usr/sbin/nginx ] + requires [ setup, seahub ] + pidfile /var/run/nginx/nginx.pid + dir /opt/seafile + stdout file [ /dev/log ] + stderr file [ /dev/stderr ] + uid 0 + gid 0 + healthchecks [ + http + ] + healthcheckfail restart +} healthcheck http { - checks [ - "http://127.0.0.1:80" - ] - interval 15 - timeout 20 + checks [ + "http://127.0.0.1:80" + ] + interval 15 + timeout 20 } healthcheck hub { - checks [ - "http://127.0.0.1:8000" - "tcp://127.0.0.1:8080", - ] - interval 15 - timeout 60 + checks [ + "http://127.0.0.1:8000" + "tcp://127.0.0.1:8080" + ] + interval 15 + timeout 60 } healthcheck server { - checks [ - "http://127.0.0.1:8082" - ] - interval 15 - timeout 15 + checks [ + "http://127.0.0.1:8082" + ] + interval 15 + timeout 15 } From 605b76798a000120d92130a34dcbbd9b3b32d52a Mon Sep 17 00:00:00 2001 From: shimunn <> Date: Fri, 19 Apr 2019 21:10:07 +0200 Subject: [PATCH 04/14] fixed panic --- riffol.conf | 65 +++++++++++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 35 deletions(-) diff --git a/riffol.conf b/riffol.conf index 415c4cf..0ba681c 100644 --- a/riffol.conf +++ b/riffol.conf @@ -11,18 +11,32 @@ application_group seafile { ] } +init seafile { + application_groups [seafile] +} + +application_group seafile { + applications [ + setup + seafile + seahub + nginx + ] +} + application setup { mode oneshot start [ /usr/bin/setup ] dir /opt/seafile env { - pass SEAF_VERSION SEAF_VERSION - pass SEAF_UPGRADE_INTERVAL SEAF_UPGRADE_INTERVAL + new { + SEAF /opt/seafile + } + pass { + SEAF_UPGRADE_INTERVAL SEAF_UPGRADE_INTERVAL + SEAF_VERSION SEAF_VERSION + } } - stdout file [ /dev/stdout ] - stderr file [ /dev/stderr ] - uid 0 - gid 0 } application seafile { @@ -30,16 +44,7 @@ application seafile { requires [ setup ] start [ /usr/bin/seafile, start ] stop [ /usr/bin/seafile, stop ] - pidfile /var/run/seafile/seafile.pid dir /opt/seafile - stdout file [ /dev/stdout ] - stderr file [ /dev/stderr ] - uid 0 - gid 0 - healthchecks [ - server - ] - healthcheckfail restart } application seahub { @@ -47,32 +52,22 @@ application seahub { requires [ setup ] start [ /usr/bin/seahub, start, 8000 ] stop [ /usr/bin/seahub, stop ] - pidfile /var/run/seafile/seahub.pid dir /opt/seafile - stdout file [ /dev/stdout ] - stderr file [ /dev/stderr ] - uid 0 - gid 0 - healthchecks [ - hub - ] - healthcheckfail restart } application nginx { - mode oneshot - start [ /usr/sbin/nginx ] + mode forking requires [ setup, seahub ] - pidfile /var/run/nginx/nginx.pid + start [ /usr/sbin/nginx ] dir /opt/seafile - stdout file [ /dev/log ] - stderr file [ /dev/stderr ] - uid 0 - gid 0 - healthchecks [ - http - ] - healthcheckfail restart +} + +healthchecks riffol { + checks [ + proc://riffol + ] + timeout 2 + interval 10000 } healthcheck http { From e0491a5b453b0e51e903afa450a0d04dce570ae1 Mon Sep 17 00:00:00 2001 From: shimunn <> Date: Sat, 20 Apr 2019 00:35:47 +0200 Subject: [PATCH 05/14] works --- Dockerfile | 3 +- riffol.conf | 17 ++++ scripts/seafile-server.sh | 194 -------------------------------------- scripts/setup.sh | 39 +++++++- scripts/upgrade.py | 11 ++- seafile.service | 3 +- 6 files changed, 62 insertions(+), 205 deletions(-) delete mode 100755 scripts/seafile-server.sh diff --git a/Dockerfile b/Dockerfile index 4c121f7..be36b8d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM rust:1.34 AS riffol_build -RUN cargo install --git https:/github.com/riboseinc/riffol +RUN cargo install riffol FROM nginx:mainline @@ -27,7 +27,6 @@ COPY --from=riffol_build /usr/local/cargo/bin/riffol /usr/sbin/ RUN ln -s /opt/seafile/seafile-server-latest/seafile.sh /usr/bin/seafile && \ ln -s /opt/seafile/seafile-server-latest/seahub.sh /usr/bin/seahub && \ - mkdir -p /var/run/seafile && \ ln -s /opt/seafile/pids /var/run/seafile COPY riffol.conf /etc/riffol.conf diff --git a/riffol.conf b/riffol.conf index 0ba681c..dbf3d8d 100644 --- a/riffol.conf +++ b/riffol.conf @@ -35,31 +35,48 @@ application setup { pass { SEAF_UPGRADE_INTERVAL SEAF_UPGRADE_INTERVAL SEAF_VERSION SEAF_VERSION + SEAF_NAME SEAF_NAME + SEAF_MYSQL SEAF_MYSQL + SEAF_MYSQL_HOST SEAF_MYSQL_HOST + SEAF_MYSQL_PORT SEAF_MYSQL_PORT + SEAF_MYSQL_USER SEAF_MYSQL_USER + SEAF_MYSQL_DB_SEAF SEAF_MYSQL_DB_SEAF + SEAF_MYSQL_DB_HUB SEAF_MYSQL_DB_HUB + SEAF_MYSQL_DB_CCNET SEAF_MYSQL_DB_CCNET } } } application seafile { mode forking + pidfile /var/run/seafile/seaf-server.pid requires [ setup ] start [ /usr/bin/seafile, start ] stop [ /usr/bin/seafile, stop ] dir /opt/seafile + healthcheck [ server ] + healthcheckfail restart } application seahub { mode forking requires [ setup ] + pidfile /var/run/seafile/seahub.pid start [ /usr/bin/seahub, start, 8000 ] stop [ /usr/bin/seahub, stop ] dir /opt/seafile + healthcheck [ hub ] + healthcheckfail restart } application nginx { mode forking + pidfile /var/run/nginx.pid requires [ setup, seahub ] start [ /usr/sbin/nginx ] dir /opt/seafile + healthcheck [ http, hub ] + healthcheckfail restart } healthchecks riffol { diff --git a/scripts/seafile-server.sh b/scripts/seafile-server.sh deleted file mode 100755 index c9bbc3c..0000000 --- a/scripts/seafile-server.sh +++ /dev/null @@ -1,194 +0,0 @@ -#!/bin/bash - -LATEST=$SEAF/seafile-server-latest -PIDS=$SEAF/pids -PIDFILES=("$PIDS" "$LATEST/runtime" "/var/run/nginx") -COMMANDS=("seaf-server $LATEST/seafile.sh start" "seahub $LATEST/seahub.sh ${SEAF_HUB_MODE:-start} 8000" "nginx /usr/sbin/nginx") - -function stop { - #Kill when hitting CTRL+C repeatedly - trap stop_kill SIGTERM - $0 stop -} -function stop_kill { - $0 kill -} -function ext_url { - echo "${SEAF_URL:-http://$(hostname)}/seafhttp" -} -function patch_seahub_conf { - KEY="FILE_SERVER_ROOT" - ENTRY="$KEY = '$(ext_url)'" - CONF="$SEAF/conf/seahub_settings.py" - grep "$KEY" -i "$CONF" - if [ $? -eq 1 ]; then - echo "Patched seahub_settings.py: set $ENTRY" - echo -e "\n$ENTRY" >> "$CONF" - fi -} -function last_update { - if [ -e "$LATEST/install_date" ]; then - date -d $(cat "$LATEST/install_date") "+%s" - else - echo 0 - fi -} - -function pid { - for LOC in ${PIDFILES[@]}; do - if [ -e "$LOC/$1.pid" ]; then - cat "$LOC/$1.pid" - return 0 - fi - done - pgrep -f "/$1" -} - -case "$1" in - run) - if [ ! -e "$LATEST" ]; then - (>&2 echo This appears to be the fist run, installing..) - mkdir -p $SEAF/conf - cp /etc/seafile/* $SEAF/conf/* -rf - $0 run-upgrade - exit $? - else - patch_seahub_conf - for CMD in "${COMMANDS[@]}"; do - INFO=($CMD) - $0 manage-component "${INFO[0]}" start "${INFO[1]}" "${INFO[@]:2}" - done - wait - fi - trap stop SIGINT SIGQUIT SIGTERM - LAST_UPGRADE=$(last_update) - UPGRADE=0 - while eval "$0 status > /dev/null"; do - sleep 10; - SINCE_UPGRADE=$(((($(date "+%s") - $LAST_UPGRADE))/(60*60*24))) - if [ $LAST_UPGRADE -gt 0 ] && [ "0$SEAF_UPGRADE_INTERVAL" -gt 0 ] && [ $SINCE_UPGRADE -gt "0$SEAF_UPGRADE_INTERVAL" ]; then - echo "It's been $SINCE_UPGRADE days since the last Upgrade\nSTOPPING TO PERFORM UPGRADE NOW\nSet SEAF_UPGRADE_INTERVAL=0 disable automatic updates" - UPGRADE=1 - $0 stop - fi - done - if [ $UPGRADE -eq 1 ]; then - $0 stop-upgrade-run - else - echo "Terminated" - fi - ;; - run-upgrade) - $0 upgrade - RES=$? - if [ $RES -eq 1 ]; then - echo "Failed upgrade" - exit 1 - fi - if [ $RES -eq 127 ]; then - #No upgrade - true - fi - if [ $RES -eq 126 ] && [ ! -e "$LATEST/install_date" ]; then - date +%Y-%m-%d > "$LATEST/install_date" - fi - $0 run - ;; - stop) - PIDS="" - for CMD in seafile-controller ccnet seafdav "${COMMANDS[@]}" seafile-controller ccnet; do - $0 manage-component $(echo $CMD | cut -d' ' -f1) stop & - PIDS="$PIDS $!" - done - wait $PIDS - ;; - kill) - export SEAF_STOP_TRIES=0 - $0 stop - ;; - stop-upgrade-run) - $0 stop && $0 upgrade && $0 run - ;; - upgrade) - /usr/local/sbin/upgrade main - kill -SIGHUP $(pgrep -o nginx) #Reload nginx - ;; - maintanance) - $0 stop - if [ "$2" = "--fsck" ]; then - $LATEST/seaf-fsck.sh - fi - if [ "$2" = "--fsck-repair" ]; then - $LATEST/seaf-fsck.sh --repair - fi - $LATEST/seaf-gc.sh - $0 start - ;; - setup) - INSTALLDIR=$2 - SETUP_ARGS="auto -n ${SEAF_NAME:-$(hostname)} -i $(hostname) -p 8082" - if [ ! -z "$SEAF_MYSQL" ]; then - $INSTALLDIR/setup-seafile-mysql.sh $SETUP_ARGS -o $SEAF_MYSQL_HOST -t ${SEAF_MYSQL_PORT:-3306} -u "${SEAF_MYSQL_USER:-root}" \ - -w "$SEAF_MYSQL_PASS" -r "${SEAF_MYSQL_ROOT_PASS:-$SEAF_MYSQL_PASS}" -c ${SEAF_MYSQL_DB_CCNET:-ccnet} -s ${SEAF_MYSQL_DB_SEAF:-seafile} \ - -b ${SEAF_MYSQL_DB_HUB:-seahub} - else - $INSTALLDIR/setup-seafile.sh $SETUP_ARGS - fi - ;; - status) - RUNNING=1 - for CMD in seafile-controller ccnet "${COMMANDS[@]}"; do - SERVICE="$(echo $CMD | cut -d' ' -f1)" - echo -n "$SERVICE: " - $0 manage-component $SERVICE status - [ $? -eq 0 ] || [ $RUNNING -eq 0 ] - RUNNING=$? - done - [ $RUNNING -eq 0 ] - ;; - manage-component) - mkdir -p /var/run/seafile - NAME="$2" - PID=$(pid $NAME) - case "$3" in - start) - CMD="$4" - ARGS="$5" - eval "$CMD $ARGS" - sleep 1 - ( ! eval "$0 $1 $NAME status" ) && ((>&2 echo Failed to start $NAME); exit 1) - ;; - status) - (kill -0 $PID 2> /dev/null && echo Running) || (echo Stopped && exit 1) - ;; - stop) - QUERY="$0 $1 $NAME status > /dev/null" - if eval "$QUERY"; then - kill $PID - TRIES=${SEAF_STOP_TRIES:-30} - while eval "$QUERY"; do - TRIES=$((TRIES - 1)) - if [ $TRIES -lt 1 ]; then - (>&2 echo Failed to stop gracefully $NAME) - kill -9 $PID - exit 1 - else - kill $PID - [ $? -eq 1 ] && break - fi - sleep 1 - done - (>&2 echo $NAME has been stopped) - else - (>&2 echo $NAME is not running) - fi - ;; - *) - echo "You're doing wrong pal" - ;; - esac - ;; - *) - (>&2 echo Unknown option $1 options include: run, run-upgrade, upgrade, stop, stop-upgrade) - ;; -esac diff --git a/scripts/setup.sh b/scripts/setup.sh index b97c30d..5b19652 100644 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -x + LATEST=$SEAF/seafile-server-latest function ext_url { @@ -23,20 +25,51 @@ function last_update { fi } +function timestamp { + date +%Y-%m-%d > "$LATEST/install_date" +} + +function revert { + rm -rf "$LATEST" +} + ### Setup ### if [ ! -e "$LATEST" ]; then (>&2 echo This appears to be the fist run, installing..) + trap revert ERR mkdir -p $SEAF/conf - cp /etc/seafile/* $SEAF/conf/* -rf + cp -f /etc/seafile/* /opt/seafile/conf/ /usr/local/sbin/upgrade main - exit $? + RES="$?" + if [ "$RES" -eq 126 ]; then + (>&2 echo Entering setup) + INSTALLDIR=$(cat $SEAF/ahead) + rm -rf $SEAF/ahead + SETUP_ARGS="auto -n ${SEAF_NAME:-$(hostname)} -i $(hostname) -p 8082" + if [ ! -z "$SEAF_MYSQL" ]; then + $INSTALLDIR/setup-seafile-mysql.sh $SETUP_ARGS -o $SEAF_MYSQL_HOST -t ${SEAF_MYSQL_PORT:-3306} -u "${SEAF_MYSQL_USER:-root}" \ + -w "$SEAF_MYSQL_PASS" -r "${SEAF_MYSQL_ROOT_PASS:-$SEAF_MYSQL_PASS}" -c ${SEAF_MYSQL_DB_CCNET:-ccnet} -s ${SEAF_MYSQL_DB_SEAF:-seafile} \ + -b ${SEAF_MYSQL_DB_HUB:-seahub} + else + $INSTALLDIR/setup-seafile.sh $SETUP_ARGS + fi + cp -f /etc/seafile/* /opt/seafile/conf/ + timestamp + exit 0 + fi + if [ ! "$RES" -eq 1 ]; then + exit 0 + fi + (>&2 echo "Installation failed") + exit 1 else LAST_UPGRADE=$(last_update) SINCE_UPGRADE=$(((($(date "+%s") - $LAST_UPGRADE))/(60*60*24))) if [ $LAST_UPGRADE -gt 0 ] && [ "0$SEAF_UPGRADE_INTERVAL" -gt 0 ] && [ $SINCE_UPGRADE -gt "0$SEAF_UPGRADE_INTERVAL" ]; then - echo "It's been $SINCE_UPGRADE days since the last Upgrade\nPERFORMING UPGRADE NOW\nSet SEAF_UPGRADE_INTERVAL=0 disable automatic updates" + (>&2 echo "It's been $SINCE_UPGRADE days since the last Upgrade\nPERFORMING UPGRADE NOW\nSet SEAF_UPGRADE_INTERVAL=0 disable automatic updates") /usr/local/sbin/upgrade main + timestamp fi patch_seahub_conf fi diff --git a/scripts/upgrade.py b/scripts/upgrade.py index 492d440..2d12d4d 100755 --- a/scripts/upgrade.py +++ b/scripts/upgrade.py @@ -55,11 +55,13 @@ def perform_upgrade_command(version,mysql=False,yes=True): scripts = os.path.join(seaf_home,"seafile-server-%s" % version, "upgrade") current = map(lambda x: int(x), current_version().split(".")) target = map(lambda x: int(x), version.split(".")) - print len(current) == 1 and current[0] == 0 if len(current) == 1 and current[0] == 0: #Not installed - print("Running installer.") - if not call(["seafile-server","setup", os.path.join(seaf_home,"seafile-server-%s" % version) ],stdout=sys.stdout, stdin=sys.stdin): - sys.exit(1) + #print("Running installer.") + #if not call(["seafile-server","setup", os.path.join(seaf_home,"seafile-server-%s" % version) ],stdout=sys.stdout, stdin=sys.stdin): + # sys.exit(1) + crumb = open(seaf_home + "/ahead", 'w') + crumb.write(os.path.join(seaf_home,"seafile-server-%s" % version)) + crumb.close() sys.exit(126) script_re = "^upgrade_(\d+).(\d+)_(\d+).(\d+)\.sh$" run = [] @@ -93,6 +95,7 @@ def download(url, version): return dest else: print("Download failed") + sys.exit(1) return 0 def install_command(url, version): diff --git a/seafile.service b/seafile.service index 01ba47e..7ff82fb 100644 --- a/seafile.service +++ b/seafile.service @@ -19,8 +19,7 @@ Environment=SEAF_UPGRADE_INTERVAL=10 ExecStartPre=/bin/mkdir -p ${ROOT_DIR} ExecStart=/usr/bin/rkt --insecure-options=image run --uuid-file-save=${ROOT_DIR}/container.uuid --dns 8.8.8.8 --inherit-env --volume volume-opt-seafile,kind=host,source=${ROOT_DIR} --port 80-tcp:8080 \ docker://repo.shimun.net/shimun/seafile --environment=SEAF_UPGRADE_INTERVAL=${SEAF_UPGRADE_INTERVAL} -ExecStartPost=/bin/bash -c "echo 'rkt enter --app=seafile $(cat '${ROOT_DIR}'/container.uuid)' > ${ROOT_DIR}/enter.sh && chmod +x ${ROOT_DIR}/enter.sh" -ExecStopPre=/bin/bash -c "rkt enter --app=seafile $(cat ${ROOT_DIR}/container.uuid) 'seafile-server stop'" +ExecStartPost=/bin/bash -c "echo 'rkt enter --app=seafile $(cat '${ROOT_DIR}'/container.uuid)' > ${ROOT_DIR}/enter.sh && chmod +x ${ROOT_DIR}/enter.sh" ExecStopPost=/bin/bash -c "rkt rm $(cat ${ROOT_DIR}/container.uuid)" ExecStopPost=/bin/rm ${ROOT_DIR}/container.uuid KillMode=mixed From e1dc715dd00ec5f15831d87135bab0a20d9e68d5 Mon Sep 17 00:00:00 2001 From: shimunn <> Date: Sat, 20 Apr 2019 00:47:33 +0200 Subject: [PATCH 06/14] fix css --- .drone.yml | 2 +- riffol.conf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.drone.yml b/.drone.yml index c72e612..cc43f3a 100644 --- a/.drone.yml +++ b/.drone.yml @@ -7,7 +7,7 @@ pipeline: docker: image: plugins/docker repo: repo.shimun.net/shimun/seafile - tag: no_media + tag: riffol registry: repo.shimun.net storage_path: /drone/.docker secrets: ["docker_username", "docker_password"] diff --git a/riffol.conf b/riffol.conf index dbf3d8d..be0431d 100644 --- a/riffol.conf +++ b/riffol.conf @@ -60,7 +60,7 @@ application seafile { application seahub { mode forking - requires [ setup ] + requires [ setup, seafile ] pidfile /var/run/seafile/seahub.pid start [ /usr/bin/seahub, start, 8000 ] stop [ /usr/bin/seahub, stop ] From 6dea22e4dda6269a1a935fd68121dd67a82196e0 Mon Sep 17 00:00:00 2001 From: shimunn <> Date: Sat, 20 Apr 2019 11:37:32 +0200 Subject: [PATCH 07/14] print error msg --- Dockerfile | 2 +- riffol.conf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index be36b8d..66a6640 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM rust:1.34 AS riffol_build -RUN cargo install riffol +RUN cargo install --git https://github.com/shimunn/riffol.git --branch print_error FROM nginx:mainline diff --git a/riffol.conf b/riffol.conf index be0431d..b6ec319 100644 --- a/riffol.conf +++ b/riffol.conf @@ -108,6 +108,6 @@ healthcheck server { checks [ "http://127.0.0.1:8082" ] - interval 15 + interval 16 timeout 15 } From d1ac73034b523f42764589c22ee0890b080ed144 Mon Sep 17 00:00:00 2001 From: shimunn <> Date: Sat, 20 Apr 2019 15:43:17 +0200 Subject: [PATCH 08/14] removed unimplemented checks [CI SKIP] --- riffol.conf | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/riffol.conf b/riffol.conf index b6ec319..445b967 100644 --- a/riffol.conf +++ b/riffol.conf @@ -84,30 +84,32 @@ healthchecks riffol { proc://riffol ] timeout 2 - interval 10000 + interval 1000 } healthcheck http { checks [ - "http://127.0.0.1:80" + tcp://127.0.0.1:80 ] - interval 15 + interval 30 timeout 20 } healthcheck hub { checks [ - "http://127.0.0.1:8000" - "tcp://127.0.0.1:8080" + tcp://127.0.0.1:8000 + tcp://127.0.0.1:8080 ] - interval 15 + interval 80 timeout 60 } healthcheck server { checks [ - "http://127.0.0.1:8082" + tcp://127.0.0.1:8082 + proc://ccnet-server + proc://seaf-server ] - interval 16 - timeout 15 + interval 10 + timeout 5 } From d05de406f8737f18b3c881b3b777419f30656308 Mon Sep 17 00:00:00 2001 From: Shimun Date: Thu, 25 Jul 2019 17:10:30 +0200 Subject: [PATCH 09/14] appropriate number for never --- scripts/setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/setup.sh b/scripts/setup.sh index 5b19652..2484835 100644 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -21,7 +21,7 @@ function last_update { if [ -e "$LATEST/install_date" ]; then date -d $(cat "$LATEST/install_date") "+%s" else - echo 0 + echo 1000000 fi } From e9e595ef6889953c30fce1afd3eacd248ead10ae Mon Sep 17 00:00:00 2001 From: Shimun Date: Thu, 25 Jul 2019 17:17:40 +0200 Subject: [PATCH 10/14] use drone cache [CI SKIP] --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index cc43f3a..a750292 100644 --- a/.drone.yml +++ b/.drone.yml @@ -11,7 +11,7 @@ pipeline: registry: repo.shimun.net storage_path: /drone/.docker secrets: ["docker_username", "docker_password"] - storage_path: /drone/.docker + storage_path: /drone/cache/.docker cache_from: ["repo.shimun.net/shimun/seafile", "repo.shimun.net/shimun/seafile:nginx-deb", "repo.shimun.net/shimun/seafile:alpine"] use_cache: true pull_image: false From 99748c70aa740fe50c3d2239d8d0b0e1f45b9fb2 Mon Sep 17 00:00:00 2001 From: Shimun Date: Thu, 25 Jul 2019 18:06:40 +0200 Subject: [PATCH 11/14] update rust --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 66a6640..bf9ef7f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM rust:1.34 AS riffol_build +FROM rust:1.36-slim AS riffol_build RUN cargo install --git https://github.com/shimunn/riffol.git --branch print_error From 6fabfb2aab0d2c912c68afc97faaf4bb96cf4049 Mon Sep 17 00:00:00 2001 From: shimun Date: Tue, 14 Apr 2020 14:15:03 +0200 Subject: [PATCH 12/14] python3 --- Dockerfile | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index bf9ef7f..23896ec 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,10 +12,14 @@ ENV SEAF=/opt/seafile COPY requirements.txt /tmp/requirements.txt -RUN apt update && apt install locales -y && apt install -y --no-install-recommends procps openssl python2.7 sqlite3 python-mysqldb python-pil curl libjansson4 libfuse2 python-pip python-pip-whl python-setuptools \ - && pip install -r /tmp/requirements.txt && apt remove -y python-pip \ +RUN apt update && apt install locales -y && apt install -y --no-install-recommends procps openssl python2.7 sqlite3 python-mysqldb python-pil curl libjansson4 libfuse2 python-pip python-pip-whl python-setuptools python3 sqlite3 python3 python3-pip python3-setuptools python3-ldap \ && rm -rf /var/lib/apt/lists/* /tmp/requirements.txt +RUN python3 -m pip install --upgrade pip && rm -r /root/.cache/pip + +RUN pip3 install --timeout=3600 click termcolor colorlog pymysql \ + django==1.11.29 && rm -r /root/.cache/pip + #ENV RIFFOL_VERSION libc-2.24 #ENV RIFFOL_HASH e6aea0a91abe74dc0892b0814a0485f16ce8b738b4672b4980b15a398c013e974d5d1b6c27eed69899196cc21014e407f7ff74ee5636a8690ebd639fe0ca5abb #RUN curl -L https://github.com/riboseinc/riffol/releases/download/0.1.0/riffol-$RIFFOL_VERSION.tar.gz -o /tmp/riffol-$RIFFOL_VERSION.tar.gz && \ From 5b07f77f538e0849a3b82354817e1fe62ebe6aa0 Mon Sep 17 00:00:00 2001 From: shimun Date: Tue, 14 Apr 2020 15:16:54 +0200 Subject: [PATCH 13/14] keep python deps current --- Dockerfile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Dockerfile b/Dockerfile index 23896ec..acc9e2c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,6 +19,10 @@ RUN python3 -m pip install --upgrade pip && rm -r /root/.cache/pip RUN pip3 install --timeout=3600 click termcolor colorlog pymysql \ django==1.11.29 && rm -r /root/.cache/pip + +ADD https://raw.githubusercontent.com/haiwen/seahub/master/requirements.txt /tmp/hub-requirements.txt + +RUN pip3 install --timeout=3600 -r /tmp/hub-requirements.txt #ENV RIFFOL_VERSION libc-2.24 #ENV RIFFOL_HASH e6aea0a91abe74dc0892b0814a0485f16ce8b738b4672b4980b15a398c013e974d5d1b6c27eed69899196cc21014e407f7ff74ee5636a8690ebd639fe0ca5abb From 33af52ff54ba861782b5ddabd107cc53371f5399 Mon Sep 17 00:00:00 2001 From: shimun Date: Tue, 14 Apr 2020 15:26:21 +0200 Subject: [PATCH 14/14] keep seafdav deps current --- Dockerfile | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index acc9e2c..567940c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,13 +23,10 @@ RUN pip3 install --timeout=3600 click termcolor colorlog pymysql \ ADD https://raw.githubusercontent.com/haiwen/seahub/master/requirements.txt /tmp/hub-requirements.txt RUN pip3 install --timeout=3600 -r /tmp/hub-requirements.txt - -#ENV RIFFOL_VERSION libc-2.24 -#ENV RIFFOL_HASH e6aea0a91abe74dc0892b0814a0485f16ce8b738b4672b4980b15a398c013e974d5d1b6c27eed69899196cc21014e407f7ff74ee5636a8690ebd639fe0ca5abb -#RUN curl -L https://github.com/riboseinc/riffol/releases/download/0.1.0/riffol-$RIFFOL_VERSION.tar.gz -o /tmp/riffol-$RIFFOL_VERSION.tar.gz && \ -# echo "$RIFFOL_HASH /tmp/riffol-$RIFFOL_VERSION.tar.gz" | sha512sum --check && \ -# tar -xvzf /tmp/riffol-$RIFFOL_VERSION.tar.gz -C /usr/sbin/ && \ -# rm /tmp/riffol-$RIFFOL_VERSION.tar.gz + +ADD https://raw.githubusercontent.com/haiwen/seafdav/master/requirements.txt /tmp/dav-requirements.txt + +RUN pip3 install --timeout=3600 -r /tmp/dav-requirements.txt COPY --from=riffol_build /usr/local/cargo/bin/riffol /usr/sbin/