-
Notifications
You must be signed in to change notification settings - Fork 15
/
entrypoint.sh
executable file
·109 lines (92 loc) · 2.52 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
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
#!/bin/bash
set -eo pipefail
[[ "${DEBUG}" == true ]] && set -x
initialize_system() {
echo "Initializing Piplin container ..."
APP_ENV=${APP_ENV:-development}
APP_DEBUG=${APP_DEBUG:-true}
DB_CONNECTION=${DB_CONNECTION:-sqlite}
DB_HOST=${DB_HOST:-piplin-mysql}
DB_DATABASE=${DB_DATABASE:-piplin}
DB_PREFIX=${DB_PREFIX}
DB_USERNAME=${DB_USERNAME:-piplin}
DB_PASSWORD=${DB_PASSWORD:-piplinpassword}
if [[ "${DB_CONNECTION}" = "mysql" ]]; then
DB_PORT=${DB_PORT:-3306}
fi
DB_PORT=${DB_PORT}
# configure env file
sed 's,{{APP_ENV}},'"${APP_ENV}"',g' -i /var/www/piplin/.env
sed 's,{{APP_DEBUG}},'"${APP_DEBUG}"',g' -i /var/www/piplin/.env
}
check_database() {
echo "Attempting to connect to database ..."
case "${DB_CONNECTION}" in
mysql)
prog="mysqladmin -h ${DB_HOST} -u ${DB_USERNAME} ${DB_PASSWORD:+-p$DB_PASSWORD} -P ${DB_PORT} status"
;;
esac
timeout=60
while ! ${prog} >/dev/null 2>&1
do
timeout=$(( timeout - 1 ))
if [[ "$timeout" -eq 0 ]]; then
echo
echo "Could not connect to database server! Aborting..."
exit 1
fi
echo -n "."
sleep 1
done
echo
}
check_config() {
case "${DB_CONNECTION}" in
mysql)
checkdbinitmysql
;;
sqlite)
checkdbinitsqlite
;;
esac
}
checkdbinitmysql() {
table=users
if [[ "$(mysql -N -s -h "${DB_HOST}" -u "${DB_USERNAME}" "${DB_PASSWORD:+-p$DB_PASSWORD}" "${DB_DATABASE}" -P "${DB_PORT}" -e \
"select count(*) from information_schema.tables where \
table_schema='${DB_DATABASE}' and table_name='${DB_PREFIX}${table}';")" -eq 1 ]]; then
echo "Table ${DB_PREFIX}${table} exists! ..."
else
echo "Table ${DB_PREFIX}${table} does not exist! ..."
init_db
fi
}
checkdbinitsqlite() {
if [ -f database/database.sqlite ]; then
echo "database/database.sqlite exists! ..."
else
echo "database/database.sqlite does not exist! ..."
touch database/database.sqlite
chmod 666 database/database.sqlite
chmod 777 database
init_db
fi
}
init_db() {
echo "Initializing Piplin database ..."
redis-server &
php artisan migrate
php artisan db:seed
redis-cli shutdown
check_config
}
start_system() {
initialize_system
check_database
check_config
echo "Starting Piplin! ..."
php artisan config:cache
/usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf
}
start_system
exit 0