-
-
Notifications
You must be signed in to change notification settings - Fork 92
/
entrypoint.sh
executable file
·51 lines (44 loc) · 1.99 KB
/
entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/sh
set -e
TEMP_CONFIG="/tmp/config.json"
# Resolve and output the below variables to /tmp/config.json
node --enable-source-maps /usr/app/dist/src/entrypoint-config.js
TZ=$(cat $TEMP_CONFIG | jq -r ".timezone")
RUN_ON_STARTUP=$(cat $TEMP_CONFIG | jq -r ".runOnStartup")
RUN_ONCE=$(cat $TEMP_CONFIG | jq -r ".runOnce")
CRON_SCHEDULE=$(cat $TEMP_CONFIG | jq -r ".cronSchedule")
if [ ! -e /etc/localtime ]; then
echo "Setting localtime: $TZ"
ln -snf /usr/share/zoneinfo/"$TZ" /etc/localtime
fi
if [ ! -e /etc/timezone ]; then
echo "Setting timezone: $TZ"
echo "$TZ" > /etc/timezone
fi
# Set the DISTRO variable
export DISTRO=$(grep '^ID=' /etc/os-release | cut -d'=' -f2)
echo "Detected distro: $DISTRO"
# If runOnStartup is set, run it once before setting up the schedule
echo "Run on startup: ${RUN_ON_STARTUP}"
if [ "$RUN_ON_STARTUP" = "true" ]; then
node --enable-source-maps /usr/app/dist/src/index.js
fi
# If runOnce is not set, schedule the process
echo "Run once: ${RUN_ONCE}"
if [ "$RUN_ONCE" = "false" ]; then
echo "Setting cron schedule as ${CRON_SCHEDULE}"
if [ "$DISTRO" = "alpine" ]; then
# Add the command to the crontab
echo "${CRON_SCHEDULE} cd /usr/app && node --enable-source-maps /usr/app/dist/src/index.js" | crontab -
# Run the cron process. The container should halt here and wait for the schedule.
/usr/sbin/crond -f -l 8
else
# Debian cron wipes the environment, so we save it to a script to load in cron
printenv | sed 's/^\(.*\)$/export \1/g' > /root/project_env.sh
# Add the command to the crontab. Debian cron doesn't ensure single instance, so we use flock to ensure it
echo "${CRON_SCHEDULE} . /root/project_env.sh && cd /usr/app && flock -n /var/lock/epicgames.lock node --enable-source-maps /usr/app/dist/src/index.js > /proc/1/fd/1 2>/proc/1/fd/2" | crontab -
# Run the cron process. The container should halt here and wait for the schedule.
cron -f
fi
fi
echo "Exiting..."