1
0
mirror of https://github.com/xzeldon/vwdump.git synced 2025-06-28 02:28:14 +03:00
vwdump/entrypoint.sh
jmqm 8573420236
Quality of life improvements (#17)
- Removed quotation marks with mounting volumes in docker-compose section.
- Replaced INFO prefix with each echo with a timestamp.
  - Subsequently, echoes that have a timestamp at the end have been adjusted to remove them.
- When deleting, it first checks if there are files to delete.
  - An appropriate echo will be shown in both circumstances.
2021-07-17 14:39:17 -05:00

44 lines
1.4 KiB
Bash
Executable File

#!/bin/sh
BACKUP_CMD="/sbin/su-exec ${UID}:${GID} /app/backup.sh"
DELETE_CMD="/sbin/su-exec ${UID}:${GID} /app/delete.sh"
LOGS_FILE="/app/log/backup.log"
# If passed "manual", run backup script once ($1 = First argument passed).
if [ "$1" = "manual" ]; then
echo "[$(date +"%F %r")] Running one-time."
$BACKUP_CMD
exit 0
fi
# Create cron jobs if root.
if [ "$(id -u)" -eq 0 ]; then
# Clear cron jobs.
echo "" | crontab -
echo "[$(date +"%F %r")] Cron jobs cleared."
# Add backup script to cron jobs.
(crontab -l 2>/dev/null; echo "$CRON_TIME $BACKUP_CMD >> $LOGS_FILE 2>&1") | crontab -
echo "[$(date +"%F %r")] Added backup script to cron jobs."
# Add delete script to cron jobs if DELETE_AFTER is not null and is greater than 0.
if [ -n "$DELETE_AFTER" ] && [ "$DELETE_AFTER" -gt 0 ]; then
(crontab -l 2>/dev/null; echo "$CRON_TIME $DELETE_CMD >> $LOGS_FILE 2>&1") | crontab -
echo "[$(date +"%F %r")] Added delete script to cron jobs."
fi
fi
# Start crond if it's not running.
pgrep crond > /dev/null 2>&1
if [ $? -ne 0 ]; then
/usr/sbin/crond -L /app/log/cron.log
fi
# Restart script as user "app:app".
if [ "$(id -u)" -eq 0 ]; then
exec su-exec app:app "$0" "$@"
fi
echo "[$(date +"%F %r")] Running automatically (${CRON_TIME})." > "$LOGS_FILE"
tail -F "$LOGS_FILE" # Keeps terminal open and writes logs.