From a2b9569610dfbf25f4e98fc37dbc653d66055fc1 Mon Sep 17 00:00:00 2001 From: Accalia Elementia Date: Sat, 13 Oct 2018 20:17:44 +0000 Subject: [PATCH] add dockerfile --- CONFIG.sh | 0 Dockerfile | 48 ++++++++++++++++++ healthcheck.sh | 39 +++++++++++++++ runodrive.sh | 130 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 217 insertions(+) create mode 100644 CONFIG.sh create mode 100644 Dockerfile create mode 100755 healthcheck.sh create mode 100755 runodrive.sh diff --git a/CONFIG.sh b/CONFIG.sh new file mode 100644 index 0000000..e69de29 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..010ee6b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,48 @@ +# I'd rather use alpine, but i get a file not found error if i do.... most annoying +FROM ubuntu + +WORKDIR /app +ADD . /app +VOLUME /data +VOLUME /home/odrive/.odrive-agent + +RUN apt-get update \ + && \ + apt-get install -y -q --no-install-recommends \ + curl ca-certificates \ + && \ + apt-get clean \ + && \ + groupadd -g 1000 odrive \ + && \ + useradd -d /home/odrive -g 1000 -m -u 1000 odrive \ + && \ + touch \ + /var/log/odriveagent.log \ + /var/log/odriveagent.1.log \ + /var/log/odrivesync.log \ + /var/log/odrivesync.1.log \ + /var/log/odriverefresh.log \ + /var/log/odriverefresh.1.log \ + /app/run.pids \ + && \ + chown odrive:odrive /app /app/* /var/log/odrive* \ + && \ + chmod ug+rwX /app /app/* /var/log/odrive* + +USER odrive + +RUN curl -L "http://dl.odrive.com/odrive-py" --create-dirs -o "/app/bin/odrive.py" \ + && \ + curl -L "http://dl.odrive.com/odriveagent-lnx-64" | tar -xvzf- -C "/app/bin/" \ + && \ + curl -L "http://dl.odrive.com/odrivecli-lnx-64" | tar -xvzf- -C "/app/bin/" \ + && \ + chmod +x /app/bin/* + +ENV ODRIVE_AUTH_TOKEN=NOAUTH +ENV ODRIVE_REMOTE_MOUNT="/" + +CMD ["/bin/bash", "/app/runodrive.sh"] +HEALTHCHECK CMD ["/bin/bash", "/app/healthcheck.sh"] + \ No newline at end of file diff --git a/healthcheck.sh b/healthcheck.sh new file mode 100755 index 0000000..98f5426 --- /dev/null +++ b/healthcheck.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +source /app/run.pids + +ERRORS=0 +if [ -n "${PID_LOGROTATE}" -a -e /proc/${PID_LOGROTATE} ]; then + echo 'SUCCESS: odrive log rotator running' +else + ((ERRORS++)) + echo 'ERROR: odrive log rotator not running' +fi +if [ -n "${PID_ODRIVEAGENT}" -a -e /proc/${PID_ODRIVEAGENT} ]; then + echo 'SUCCESS: odrive agent running' +else + ((ERRORS++)) + echo 'ERROR: odrive agent not running' +fi +if [ -n "${PID_ODRIVEREFRESH}" -a -e /proc/${PID_ODRIVEREFRESH} ]; then + echo 'SUCCESS: odrive refresh running' +else + ((ERRORS++)) + echo 'ERROR: odrive refresh not running' +fi +if [ -n "${PID_ODRIVETRASH}" -a -e /proc/${PID_ODRIVETRASH} ]; then + echo 'SUCCESS: odrive empty trash running' +else + ((ERRORS++)) + echo 'ERROR: odrive empty trash not running' +fi +if [ -n "${PID_ODRIVESYNC}" -a -e /proc/${PID_ODRIVESYNC} ]; then + echo 'SUCCESS: odrive sync running' +else + ((ERRORS++)) + echo 'ERROR: odrive sync not running' +fi + +if [ "${ERRORS}" -gt 0 ]; then + exit 1 +fi \ No newline at end of file diff --git a/runodrive.sh b/runodrive.sh new file mode 100755 index 0000000..260f66d --- /dev/null +++ b/runodrive.sh @@ -0,0 +1,130 @@ +#!/bin/bash + +APPDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" +PATH="${APPDIR}/bin:${PATH}" +PID_ODRIVEAGENT='' +PID_ODRIVEREFRESH='' +PID_ODRIVETRASH='' +PID_ODRIVESYNC='' +PID_LOGROTATE='' + +function initOneDrive() { + local INIT_FIRST=0 + if [ ! -e /home/odrive/.odrive-agent/db/odrive.db -a "${ODRIVE_AUTH_TOKEN}" = "NOAUTH" ]; then + INIT_FIRST=1 + echo "NO AUTHENTICATION TOKEN PROVIDED. CANNOT RUN" >&2 + exit 1 + fi + odriveagent &>/var/log/odriveagent.log & + PID_ODRIVEAGENT=$! + sleep 2s; + if [ "${INIT_FIRST}" = "1" ]; then + odrive authenticate "${ODRIVE_AUTH_TOKEN}" + odrive mount /data "${ODRIVE_REMOTE_MOUNT}" + sleep 5s + fi +} + +function refreshMount() { + while true; do + echo "" >> /var/log/odriverefresh.log + date >> /var/log/odriverefresh.log + echo "Initiating Refresh of data" >> /var/log/odriverefresh.log + find /data -type d -print0 |xargs -r0 -n1 odrive refresh &>> /var/log/odriverefresh.log + echo "" >> /var/log/odriverefresh.log + date >> /var/log/odriverefresh.log + echo "Completed Refresh of data" >> /var/log/odriverefresh.log + sleep 6h; + done +} + +function emptyTrash() { + while true; do + echo "" >> /var/log/odriverefresh.log + date >> /var/log/odriverefresh.log + echo "Initiating emptying of trash" >> /var/log/odriverefresh.log + odrive emptytrash &>> /var/log/odriverefresh.log + echo "" >> /var/log/odriverefresh.log + date >> /var/log/odriverefresh.log + echo "Completed emptying of trash" >> /var/log/odriverefresh.log + sleep 1h; + done +} + +function syncMount() { + while true; do + echo "" >> /var/log/odrivesync.log + date >> /var/log/odrivesync.log + echo "Initiating Sync of data" >> /var/log/odrivesync.log + find /data -iname '*.cloudf' -print0 -o -iname '*.cloud' -print0 |xargs -r0 -n1 odrive sync &>> /var/log/odrivesync.log + echo "" >> /var/log/odrivesync.log + date >> /var/log/odrivesync.log + echo "Completed Sync of data" >> /var/log/odrivesync.log + sleep 5m; + done +} + +function logRotate() { + while true; do + sleep 24h; + cp /var/log/odriveagent.log /var/log/odriveagent.1.log; + > /var/log/odriveagent.log; + cp /var/log/odrivesync.log /var/log/odrivesync.1.log; + > /var/log/odrivesync.log; + cp /var/log/odriverefresh.log /var/log/odriverefresh.1.log; + > /var/log/odriverefresh.log; + done; +} + + +initOneDrive; + +logRotate & +PID_LOGROTATE=$! + +refreshMount & +PID_ODRIVEREFRESH=$! + +sleep 1m + +syncMount & +PID_ODRIVESYNC=$! +emptyTrash & +PID_ODRIVETRASH=$! + +cat > /app/run.pids <> /var/log/odriveagent.log + echo 'ERROR: odrive log rotator not running' >>/var/log/odriveagent.log + break; + fi + if [ -z "${PID_ODRIVEAGENT}" -o ! -e /proc/${PID_ODRIVEAGENT} ]; then + date >> /var/log/odriveagent.log + echo 'ERROR: odrive agent not running' >>/var/log/odriveagent.log + break; + fi + if [ -z "${PID_ODRIVEREFRESH}" -o ! -e /proc/${PID_ODRIVEREFRESH} ]; then + date >> /var/log/odriveagent.log + echo 'ERROR: odrive refresh not running' >>/var/log/odriveagent.log + break; + fi + if [ -z "${PID_ODRIVETRASH}" -o ! -e /proc/${PID_ODRIVETRASH} ]; then + date >> /var/log/odriveagent.log + echo 'ERROR: odrive empty trash not running' >>/var/log/odriveagent.log + break; + fi + if [ -z "${PID_ODRIVESYNC}" -o ! -e /proc/${PID_ODRIVESYNC} ]; then + date >> /var/log/odriveagent.log + echo 'ERROR: odrive sync not running' >>/var/log/odriveagent.log + break; + fi + sleep 1m; +done \ No newline at end of file