Minor alterations to ddevcontainer.

This commit is contained in:
Adam Outler
2025-10-16 00:09:07 +00:00
parent de92c9563e
commit f57ec74cc1
9 changed files with 121 additions and 80 deletions

View File

@@ -24,6 +24,26 @@ SERVICES=""
FAILED_NAME=""
FAILED_STATUS=0
is_pid_active() {
pid="$1"
[ -z "${pid}" ] && return 1
if ! kill -0 "${pid}" 2>/dev/null; then
return 1
fi
if [ -r "/proc/${pid}/status" ]; then
state_line=$(grep '^State:' "/proc/${pid}/status" 2>/dev/null || true)
case "${state_line}" in
*"(zombie)"*|*"(dead)"*)
return 1
;;
esac
fi
return 0
}
add_service() {
script="$1"
name="$2"
@@ -48,7 +68,7 @@ shutdown_services() {
for entry in ${SERVICES}; do
pid="${entry%%:*}"
[ -z "${pid}" ] && continue
if kill -0 "${pid}" 2>/dev/null; then
if is_pid_active "${pid}"; then
kill "${pid}" 2>/dev/null || true
fi
done
@@ -108,7 +128,7 @@ while [ -n "${SERVICES}" ]; do
pid="${entry%%:*}"
name="${entry#*:}"
[ -z "${pid}" ] && continue
if ! kill -0 "${pid}" 2>/dev/null; then
if ! is_pid_active "${pid}"; then
wait "${pid}" 2>/dev/null
status=$?
FAILED_STATUS=$status

View File

@@ -1,16 +1,10 @@
#!/bin/sh
# first-run-check.sh - Checks and initializes configuration files on first run
# Check for app.conf
# Check for app.conf and deploy if required
if [ ! -f /app/config/app.conf ]; then
mkdir -p /app/config
cp /app/back/app.conf /app/config/app.conf
echo "🆕 First run detected: Default configuration initialized." >&2
fi
# Check for app.db
if [ ! -f /app/db/app.db ]; then
mkdir -p /app/db
cp /app/back/app.db /app/db/app.db
echo "🆕 First run detected: Fresh database created." >&2
fi

View File

@@ -1,9 +1,14 @@
#!/bin/sh
# This script checks if the database file exists, and if not, creates it with the initial schema.
# It is intended to be run at the first start of the application.
test -f "${NETALERTX_DB}/app.db" && exit 0
# if the db exists, exit
test -f "${NETALERTX_DB_FILE}" && exit 0
echo "First run detected, creating initial database schema in ${NETALERTX_DB}/app.db"
echo "First run detected, creating initial database schema in ${NETALERTX_DB_FILE}"
cat << end-of-database > ${NETALERTX_DB}/db.sql
# Write all text to db file until we see "end-of-database-schema"
cat << end-of-database-schema > ${NETALERTX_DB_FILE}
CREATE TABLE sqlite_stat1(tbl,idx,stat);
CREATE TABLE Events (eve_MAC STRING (50) NOT NULL COLLATE NOCASE, eve_IP STRING (50) NOT NULL COLLATE NOCASE, eve_DateTime DATETIME NOT NULL, eve_EventType STRING (30) NOT NULL COLLATE NOCASE, eve_AdditionalInfo STRING (250) DEFAULT (''), eve_PendingAlertEmail BOOLEAN NOT NULL CHECK (eve_PendingAlertEmail IN (0, 1)) DEFAULT (1), eve_PairEventRowid INTEGER);
CREATE TABLE Sessions (ses_MAC STRING (50) COLLATE NOCASE, ses_IP STRING (50) COLLATE NOCASE, ses_EventTypeConnection STRING (30) COLLATE NOCASE, ses_DateTimeConnection DATETIME, ses_EventTypeDisconnection STRING (30) COLLATE NOCASE, ses_DateTimeDisconnection DATETIME, ses_StillConnected BOOLEAN, ses_AdditionalInfo STRING (250));
@@ -415,6 +420,7 @@ CREATE TRIGGER "trg_delete_devices"
'delete'
);
END;
end-of-database
end-of-database-schema
sqlite3 ${NETALERTX_DB}/app.db < ${NETALERTX_DB}/db.sql
# Import the database schema into the new database file
sqlite3 ${NETALERTX_DB_FILE} < ${NETALERTX_DB}/db.sql

View File

@@ -7,8 +7,8 @@ export INSTALL_DIR=/app
if grep -q "cron_restart_backend" "${LOG_EXECUTION_QUEUE}"; then
# Restart python application using s6
killall python3
sleep 2
/services/start-backend.sh &
echo 'done'
# Remove all lines containing cron_restart_backend from the log file
sed -i '/cron_restart_backend/d' "${LOG_EXECUTION_QUEUE}"

View File

@@ -24,8 +24,8 @@ done
trap cleanup EXIT
trap forward_signal INT TERM
echo "/usr/sbin/php-fpm83 -y \"${PHP_FPM_CONFIG_FILE}\" -F >>\"${LOG_APP_PHP_ERRORS}\" 2>&1 &"
/usr/sbin/php-fpm83 -y "${PHP_FPM_CONFIG_FILE}" -F >>"${LOG_APP_PHP_ERRORS}" 2>&1 &
echo "/usr/sbin/php-fpm83 -y \"${PHP_FPM_CONFIG_FILE}\" -F 2>&1 >>\"${LOG_APP_PHP_ERRORS}\" &"
/usr/sbin/php-fpm83 -y "${PHP_FPM_CONFIG_FILE}" -F 2>&1 >>"${LOG_APP_PHP_ERRORS}" &
php_fpm_pid=$!
wait "${php_fpm_pid}"