add dockerfile

This commit is contained in:
Accalia Elementia 2018-10-13 20:17:44 +00:00
parent 310511864b
commit a2b9569610
No known key found for this signature in database
GPG Key ID: 0C18DFF66BD2DF7D
4 changed files with 217 additions and 0 deletions

0
CONFIG.sh Normal file
View File

48
Dockerfile Normal file
View File

@ -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"]

39
healthcheck.sh Executable file
View File

@ -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

130
runodrive.sh Executable file
View File

@ -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 <<PIDS
PID_ODRIVEAGENT=${PID_ODRIVEAGENT}
PID_ODRIVEREFRESH=${PID_ODRIVEREFRESH}
PID_ODRIVESYNC=${PID_ODRIVESYNC}
PID_ODRIVETRASH=${PID_ODRIVETRASH}
PID_LOGROTATE=${PID_LOGROTATE}
PIDS
while true; do
if [ -z "${PID_LOGROTATE}" -o ! -e /proc/${PID_LOGROTATE} ]; then
date >> /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