-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathdocker-entrypoint.sh
117 lines (92 loc) · 2.39 KB
/
docker-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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/bash
# Terminate the script immediately on error
set -e
###########################################
# Docker Entrypoint
###########################################
# Output colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
# Success log function
log_success() {
echo -e "${GREEN}[✓] $1${NC}"
}
# Error log function
log_error() {
echo -e "${RED}[✗] $1${NC}"
exit 1
}
# Info log function
log_info() {
echo -e "${YELLOW}[i] $1${NC}"
}
echo -e "\n${YELLOW}=== Starting Marreta ===${NC}\n"
# Environment Variables Configuration
log_info "Configuring environment variables..."
# Env file (.env)
ENV_FILE="/app/.env"
# Clean Env file
> "$ENV_FILE"
while IFS='=' read -r key value; do
# If value contains spaces and is not already quoted, add quotes
if [[ "$value" =~ \ ]] && ! [[ "$value" =~ ^\".*\"$ ]]; then
value="\"$value\""
fi
echo "$key=$value" >> "$ENV_FILE"
done < <(env)
log_success "Environment variables configured"
# Permissions Adjustment
log_info "Adjusting directory permissions..."
mkdir -p /app/cache /app/logs # Ensures directories exist
chown -R www-data:www-data /app/cache /app/logs
chmod -R 775 /app/cache /app/logs
log_success "Permissions adjusted"
# Service Check Functions
check_nginx() {
if ! pgrep nginx > /dev/null; then
log_error "Failed to start Nginx"
else
log_success "Nginx started successfully"
fi
}
check_php_fpm() {
if ! pgrep php-fpm > /dev/null; then
log_error "Failed to start PHP-FPM"
else
log_success "PHP-FPM started successfully"
fi
}
# Services Initialization
echo -e "\n${YELLOW}=== Starting services ===${NC}\n"
# PHP-FPM Directory
if [ ! -d /var/run/php ]; then
log_info "Creating PHP-FPM directory..."
mkdir -p /var/run/php
chown -R www-data:www-data /var/run/php
log_success "PHP-FPM directory created"
fi
# Starting PHP-FPM
log_info "Starting PHP-FPM..."
php-fpm &
sleep 3
check_php_fpm
# Checking Nginx configuration
log_info "Checking Nginx configuration..."
nginx -t
if [ $? -ne 0 ]; then
log_error "Invalid Nginx configuration"
else
log_success "Valid Nginx configuration"
fi
# Starting Nginx
log_info "Starting Nginx..."
nginx -g "daemon off;" &
sleep 3
check_nginx
echo -e "\n${GREEN}=== Marreta initialized ===${NC}\n"
# Wait for any process to exit
wait -n
# Exit with status of process that exited first
exit $?