-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom-entrypoint.sh
95 lines (76 loc) · 2.58 KB
/
custom-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
#!/bin/sh
source /root/magento_config
VERSION=""
if [ -f composer.json ]; then
VERSION=$(grep -oP '"version":\s*"\K[^"]+' composer.json)
VERSION=" $VERSION"
fi
if [ ! $PORT ]; then
PORT=$DEFAULT_PORT
fi
if [ ! $HOST ]; then
HOST="localhost"
fi
wait_for_elasticsearch() {
local start_time=$(date +%s)
local end_time=$((start_time + 120))
while ! nc -z localhost 9200 >/dev/null 2>&1; do
current_time=$(date +%s)
if [ "$current_time" -ge "$end_time" ]; then
echo "Elasticsearch Timeout!"
exit 1
fi
sleep 1
done
}
echo -e "\n\n\e[34m __ __ _ \e[0m"
echo -e "\e[34m| \/ | __ _ __ _ ___ _ __ | |_ ___ \e[0m"
echo -e "\e[34m| |\/| |/ _\` |/ _\` |/ _ \ '_ \| __/ _ \ \e[0m"
echo -e "\e[34m| | | | (_| | (_| | __/ | | | || (_) |\e[0m"
echo -e "\e[34m|_| |_|\__,_|\__, |\___|_| |_|\__\___/ \e[0m"
echo -e "\e[34m |___/ \e[0m\n\n"
# Start elasticsearch
echo -n "Start elasticsearch..."
su elasticsearch -c 'start_elasticsearch'
wait_for_elasticsearch
echo -e "\e[32mok\e[0m"
# Start mysql
echo -n "Start mysql..."
service mysql start > /dev/null 2>&1
echo -e "\e[32mok\e[0m"
# Start nginx
echo -n "Start nginx..."
service nginx start > /dev/null 2>&1
echo -e "\e[32mok\e[0m"
# Start php-fpm
echo -n "Start php-fpm..."
service $PHP_FPM_SERVICE start > /dev/null 2>&1
$PHP_FPM_CLI -D -R > /dev/null 2>&1
echo -e "\e[32mok\e[0m"
# Testing
curl -s http://localhost:$DEFAULT_PORT | grep -q "magento-init"
if [ $? -eq 0 ]; then
if [[ "$HOST" != "localhost" || "$PORT" != "$DEFAULT_PORT" ]]; then
# Update host
echo -n "Update base url..."
mysql -u root -proot magento_db -e "UPDATE core_config_data SET value = 'http://$HOST:$PORT/' WHERE path = 'web/unsecure/base_url';" > /dev/null 2>&1
echo -e "\e[32mok\e[0m"
# Restart nginx
echo "listen $PORT default_server; server_name $HOST;" > /etc/nginx/host.conf
echo -n "Restart nginx..."
service nginx restart > /dev/null 2>&1
echo -e "\e[32mok\e[0m"
# Flush cache
echo -n "Flush cache..."
bin/magento cache:flush > /dev/null 2>&1
echo -e "\e[32mok\e[0m"
fi
echo -e "\n\e[32mMagento$VERSION is ready to use.\e[0m"
echo -e "➞ Customer View: \e[34mhttp://$HOST:$PORT/\e[0m"
echo -e "➞ Admin: \e[34mhttp://$HOST:$PORT/admin/\e[0m (admin/admin123)"
echo -e "\e[33mWarning: Data will be lost if you exit this session.\e[0m\n"
else
echo -e "\e[31mSetup failed!\e[0m"
exit 1
fi
exec "$@"