Skip to content

Commit 14df36f

Browse files
committed
Do not run php in foreground
1 parent d98ac9c commit 14df36f

1 file changed

Lines changed: 55 additions & 22 deletions

File tree

actions/entrypoint.sh

Lines changed: 55 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ password=${MYSQL_ADMIN_PASSWORD:-root}
1515
user=${MYSQL_ADMIN_LOGIN:-root}
1616
password=${MYSQL_ADMIN_PASSWORD:-root}
1717
EOF
18+
chmod 600 /root/.my.cnf || true
1819

1920
log "> Writing /etc/bluecherry.conf"
2021
cat >/etc/bluecherry.conf <<EOF
@@ -24,7 +25,7 @@ bluecherry:
2425
{
2526
db:
2627
{
27-
type = 2;
28+
type = 2; # 0=sqlite, 1=pgsql, 2=mysql
2829
dbname = "${BLUECHERRY_DB_NAME:-bluecherry}";
2930
user = "${BLUECHERRY_DB_USER:-bluecherry}";
3031
password = "${BLUECHERRY_DB_PASSWORD:-bluecherry}";
@@ -38,35 +39,47 @@ EOF
3839
# 2) Permissions
3940
# -------------------------------
4041
install -d -m 0775 /var/lib/bluecherry/recordings
41-
chown bluecherry:bluecherry /var/lib/bluecherry/recordings || true
42-
chmod ug+rwx /var/lib/bluecherry/recordings
42+
chown "${BLUECHERRY_LINUX_USER_NAME:-bluecherry}":"${BLUECHERRY_LINUX_GROUP_NAME:-bluecherry}" /var/lib/bluecherry/recordings || true
43+
chmod ug+rwx /var/lib/bluecherry/recordings || true
4344

45+
# Route container logs to stdout safely
4446
chmod 777 /proc/self/fd/1 || true
4547

4648
# -------------------------------
47-
# 3) Ancillary services
49+
# 3) Ancillary services (warn-only)
4850
# -------------------------------
4951
log "> Starting rsyslogd"
5052
/usr/sbin/rsyslogd || log "WARN: rsyslogd failed (continuing)"
5153

52-
# PHP-FPM (try 8.3 → 8.2 → 8.1)
54+
# PHP-FPM (try 8.3 → 8.2 → 8.1), **daemonized** (no -F)
55+
PHPFPM_STARTED=0
5356
for v in 8.3 8.2 8.1; do
5457
if command -v "php-fpm${v}" >/dev/null 2>&1; then
5558
log "> Starting php-fpm${v}"
56-
"php-fpm${v}" -F || log "WARN: php-fpm${v} failed (continuing)"
57-
sock="/run/php/php${v}-fpm.sock"
58-
if [ -S "$sock" ]; then
59-
ln -sf "$sock" /etc/alternatives/php-fpm.sock
59+
if "php-fpm${v}"; then
60+
sock="/run/php/php${v}-fpm.sock"
61+
if [ -S "$sock" ]; then
62+
ln -sf "$sock" /etc/alternatives/php-fpm.sock || true
63+
fi
64+
PHPFPM_STARTED=1
65+
else
66+
log "WARN: php-fpm${v} failed (continuing)"
6067
fi
6168
break
6269
fi
6370
done
71+
[ "$PHPFPM_STARTED" -eq 1 ] || log "WARN: no php-fpm found; UI may not work"
6472

65-
log "> Starting nginx"
66-
nginx || log "WARN: nginx failed (continuing)"
73+
# nginx (optional)
74+
if command -v nginx >/dev/null 2>&1; then
75+
log "> Starting nginx"
76+
nginx || log "WARN: nginx failed (continuing)"
77+
else
78+
log "WARN: nginx not installed; UI may be unreachable"
79+
fi
6780

6881
# -------------------------------
69-
# 4) Database wait + migrate/create
82+
# 4) Database wait + create/upgrade
7083
# -------------------------------
7184
DB_HOST="${BLUECHERRY_DB_HOST:-bc-mysql}"
7285
DB_NAME="${BLUECHERRY_DB_NAME:-bluecherry}"
@@ -78,36 +91,55 @@ for i in {1..60}; do
7891
mysql -h "$DB_HOST" -e "SELECT 1" >/dev/null 2>&1 && break
7992
sleep 1
8093
done
94+
log "> DB is up."
8195

96+
# Create or upgrade
8297
if mysql -h "$DB_HOST" -e "USE \`$DB_NAME\`" >/dev/null 2>&1; then
8398
log "> DB exists → upgrading"
84-
/bin/bc-database-upgrade "$DB_NAME" "$DB_USER" "$DB_PASS" "$DB_HOST" || { log "DB upgrade failed"; exit 1; }
99+
/bin/bc-database-upgrade "$DB_NAME" "$DB_USER" "$DB_PASS" "$DB_HOST" || { log "ERROR: DB upgrade failed"; exit 1; }
85100
else
86101
log "> DB missing → creating"
87-
/bin/bc-database-create "$DB_NAME" "$DB_USER" "$DB_PASS" "$DB_HOST" || { log "DB create failed"; exit 1; }
102+
/bin/bc-database-create "$DB_NAME" "$DB_USER" "$DB_PASS" "$DB_HOST" || { log "ERROR: DB create failed"; exit 1; }
88103
fi
89104

105+
# Ensure required privileges (MySQL 8-safe); warn if it fails
106+
log "> Ensuring '${DB_USER}' has PROCESS/SHOW VIEW/EVENT/TRIGGER/LOCK TABLES and native auth"
107+
{
108+
mysql -h "$DB_HOST" -uroot -p"${MYSQL_ADMIN_PASSWORD:-root}" -e \
109+
"GRANT PROCESS, SHOW VIEW, EVENT, TRIGGER, LOCK TABLES ON *.* TO '${DB_USER}'@'${BLUECHERRY_DB_ACCESS_HOST:-%}';"
110+
mysql -h "$DB_HOST" -uroot -p"${MYSQL_ADMIN_PASSWORD:-root}" -e \
111+
"ALTER USER '${DB_USER}'@'${BLUECHERRY_DB_ACCESS_HOST:-%}' IDENTIFIED WITH mysql_native_password BY '${DB_PASS}';"
112+
mysql -h "$DB_HOST" -uroot -p"${MYSQL_ADMIN_PASSWORD:-root}" -e "FLUSH PRIVILEGES;"
113+
} || log 'WARN: grant/alter failed; continuing'
114+
90115
# -------------------------------
91116
# 5) Start bc-server
92117
# -------------------------------
93118
log "> Starting bc-server"
94-
95119
export LD_LIBRARY_PATH=/usr/lib/bluecherry
96120
BC_ARGS=(-u "${BLUECHERRY_LINUX_USER_NAME:-bluecherry}" -g "${BLUECHERRY_LINUX_GROUP_NAME:-bluecherry}")
97121

98122
if [ "${DEBUG:-0}" = "1" ]; then
99123
log "Running bc-server in DEBUG mode (log level debug)"
100124
exec /usr/sbin/bc-server "${BC_ARGS[@]}" -l d
101-
else
102-
log "Running bc-server in normal mode"
103-
/usr/sbin/bc-server "${BC_ARGS[@]}" &
104-
BC_PID=$!
105125
fi
106126

127+
# Normal mode: foreground process started in background, watchdog monitors it
128+
/usr/sbin/bc-server "${BC_ARGS[@]}" &
129+
BC_PID=$!
130+
107131
# -------------------------------
108-
# 6) Watchdog loop (bc-server only fails container)
132+
# 6) Watchdog loop (fail only if bc-server dies)
109133
# -------------------------------
110134
log "All services launched. Entering watchdog loop."
135+
136+
# Allow disabling watchdog for deep debugging
137+
if [ "${DISABLE_WATCHDOG:-0}" = "1" ]; then
138+
log "Watchdog disabled (DISABLE_WATCHDOG=1)."
139+
# Keep container alive
140+
tail -f /dev/null
141+
fi
142+
111143
SLEEP="${WATCHDOG_INTERVAL:-5}"
112144
while sleep "$SLEEP"; do
113145
if ! kill -0 "${BC_PID:-0}" 2>/dev/null; then
@@ -116,6 +148,7 @@ while sleep "$SLEEP"; do
116148
log "bc-server exited (code=$EXIT). Exiting container."
117149
exit 1
118150
fi
119-
pgrep -x nginx >/dev/null || log "WARN: nginx not running"
120-
pgrep -x rsyslogd >/dev/null || log "WARN: rsyslogd not running"
151+
# Ancillary warn-only
152+
pgrep -x nginx >/dev/null || log "WARN: nginx not running (transient?)"
153+
pgrep -x rsyslogd >/dev/null || log "WARN: rsyslogd not running (transient?)"
121154
done

0 commit comments

Comments
 (0)