Skip to content

Commit

Permalink
Create cronjob from entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
maruina committed Jun 9, 2021
1 parent 323094a commit 9cdfbff
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
3 changes: 0 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ RUN apt-get update && \
pip install --no-cache-dir git+https://github.com/jaroslawhartman/withings-sync.git@"${WITHINGS_SYNC_COMMIT}"

COPY entrypoint.sh /entrypoint.sh
COPY withings-sync /etc/cron.d/withings-sync

RUN chmod 0644 /etc/cron.d/withings-sync

ENTRYPOINT ["/tini", "--"]
CMD ["/entrypoint.sh"]
15 changes: 14 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

set -eu

garmin_username="${GARMIN_USERNAME:-UNSET}"
garmin_password="${GARMIN_PASSWORD:-UNSET}"
env_file="/root/env.sh"
cron_file="/etc/cron.d/withings-sync"

# trap ctrl-c and call ctrl_c()
trap ctrl_c INT

Expand All @@ -14,7 +19,15 @@ echo "Starting cron..."
/etc/init.d/cron start

echo "Setting environment variables for cron..."
printenv | sed 's/^\(.*\)$/export \1/g' > /root/cron_env.sh
touch "${env_file}"
echo "export GARMIN_USERNAME=${garmin_username}" >> "${env_file}"
echo "export GARMIN_PASSWORD=${garmin_password}" >> "${env_file}"

echo "Setting up cronjob..."
cat << EOF > "${cron_file}"
0 10 * * * root . "${env_file}"; /usr/local/bin/withings-sync -v >> /var/log/withings-sync.log 2>&1
EOF
chmod 0644 "${cron_file}"

while true;
do
Expand Down
1 change: 0 additions & 1 deletion withings-sync

This file was deleted.

0 comments on commit 9cdfbff

Please sign in to comment.