forked from cachethq/Docker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
executable file
·114 lines (98 loc) · 2.95 KB
/
entrypoint.sh
File metadata and controls
executable file
·114 lines (98 loc) · 2.95 KB
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
#!/bin/bash
set -o errexit -o nounset -o pipefail
[ "${DEBUG:-false}" == true ] && set -x
check_database_connection() {
case "${DB_DRIVER}" in
mysql)
prog="mysqladmin -h ${DB_HOST} -u ${DB_USERNAME} ${DB_PASSWORD:+-p$DB_PASSWORD} -P ${DB_PORT} status"
;;
pgsql)
prog="/usr/bin/pg_isready"
prog="${prog} -h ${DB_HOST} -p ${DB_PORT} -U ${DB_USERNAME} -d ${DB_DATABASE} -t 1"
;;
sqlite)
prog="touch /var/www/html/database/database.sqlite"
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
}
checkdbinitmysql() {
table=sessions
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
}
checkdbinitpsql() {
table=sessions
export PGPASSWORD=${DB_PASSWORD}
if [[ "$(psql -h "${DB_HOST}" -p "${DB_PORT}" -U "${DB_USERNAME}" -d "${DB_DATABASE}" -c "SELECT to_regclass('${DB_PREFIX}${table}');" | grep -c "${DB_PREFIX}${table}")" -eq 1 ]]; then
echo "Table ${DB_PREFIX}${table} exists! ..."
else
echo "Table ${DB_PREFIX}${table} does not exist! ..."
init_db
fi
}
check_configured() {
case "${DB_DRIVER}" in
mysql)
checkdbinitmysql
;;
pgsql)
checkdbinitpsql
;;
esac
}
initialize_system() {
echo "Initializing Cachet container ..."
env_file="/var/www/html/.env"
while IFS= read -r var; do
# Extract key and value from the environment variable
key=$(echo "$var" | cut -d= -f1)
value=$(echo "$var" | cut -d= -f2- | sed 's/[]\/&]/\\&/g')
# Search for the key in the .env file with optional leading "#" and trailing spaces around "="
if grep -E -q "^\s*#?\s*$key\s*=.*" "$env_file"; then
# Replace the line with the desired format (remove "#" and set the value)
sed -E "s/^\s*#?\s*$key\s*=.*/${key} = $value/" -i "$env_file"
fi
done < <(env)
rm -rf bootstrap/cache/*
}
init_db() {
echo "Initializing Cachet database ..."
php artisan key:generate --no-interaction
}
migrate_db() {
force=""
if [[ "${FORCE_MIGRATION:-false}" == true ]]; then
force="--force"
fi
php artisan migrate ${force} --no-interaction
}
start_system() {
initialize_system
migrate_db
php artisan config:cache
php artisan vendor:publish --tag=livewire:assets
php artisan vendor:publish --tag=cachet
php artisan filament:assets
echo "Starting Cachet! ..."
/usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf
}
start_system
exit 0