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