-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·60 lines (46 loc) · 1.82 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
52
53
54
55
56
57
58
59
60
#!/bin/sh
# Get the group ID of the docker group on the host
DOCKER_GID=$(stat -c '%g' /var/run/docker.sock 2>/dev/null)
if [ -z "$DOCKER_GID" ]; then
echo "Docker socket not found. Skipping Docker group setup."
echo "Note: If you are trying to run the app with Docker capabilities, ensure that you mount the Docker socket using -v /var/run/docker.sock:/var/run/docker.sock."
else
# Remove existing docker group and create a new one with the correct GID
if getent group docker > /dev/null; then
delgroup docker
fi
addgroup -g ${DOCKER_GID} docker
# Add the node user to the docker group
addgroup node docker
fi
# Change the ownership of the application files to the node user
chown -R node:node /app
# Setup cron job if enabled
if [ "$SHUTDOWN_ENABLED" = "true" ]; then
# Set the timezone if provided
if [ -n "$TZ" ]; then
echo "Setting timezone to $TZ..."
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
fi
echo "Setting up cron jobs..."
# Create the cron job file in /etc/crontabs/root
cat <<EOF > /etc/crontabs/root
# Cron jobs
# Shutdown services at specified time
$SHUTDOWN_TIME /usr/local/bin/shutdown-services.sh >> /var/log/cron/cron.log 2>&1
EOF
# Ensure the crontab file has correct ownership and permissions
chown root:root /etc/crontabs/root
chmod 600 /etc/crontabs/root
# Ensure the log directory exists and is writable
mkdir -p /var/log/cron
touch /var/log/cron/cron.log
chown root:root /var/log/cron/cron.log
chmod 644 /var/log/cron/cron.log
# Start the cron daemon with adjusted logging level to suppress unwanted messages
crond -b -l 6 -L /var/log/cron/cron.log
# Tail the cron log to stdout so it appears in Docker logs
tail -F /var/log/cron/cron.log &
fi
# Switch to node user and run the main container command
exec su-exec node "$@"