Minimize differences between devcontainer and production

This commit is contained in:
Adam Outler
2025-10-06 23:31:20 +00:00
parent 290b6c6f3b
commit 558ab44d3f
28 changed files with 477 additions and 730 deletions

View File

@@ -60,20 +60,20 @@ isRamDisk() {
# Setup source directory
configure_source() {
echo "[1/4] Configuring System..."
echo " -> Setting up /services permissions"
echo " -> Setting up /services permissions"
sudo chown -R netalertx /services
echo "[2/4] Configuring Source..."
echo " -> Cleaning up previous instances"
echo " -> Cleaning up previous instances"
test -e ${NETALERTX_LOG} && sudo umount "${NETALERTX_LOG}" 2>/dev/null || true
test -e ${NETALERTX_API} && sudo umount "${NETALERTX_API}" 2>/dev/null || true
test -e ${NETALERTX_APP} && sudo rm -Rf ${NETALERTX_APP}/
echo " -> Linking source to ${NETALERTX_APP}"
echo " -> Linking source to ${NETALERTX_APP}"
sudo ln -s ${SOURCE_DIR}/ ${NETALERTX_APP}
echo " -> Mounting ramdisks for /log and /api"
echo " -> Mounting ramdisks for /log and /api"
mkdir -p ${NETALERTX_LOG} ${NETALERTX_API}
sudo mount -o uid=$(id -u netalertx),gid=$(id -g netalertx),mode=775 -t tmpfs -o size=256M tmpfs "${NETALERTX_LOG}"
sudo mount -o uid=$(id -u netalertx),gid=$(id -g netalertx),mode=775 -t tmpfs -o size=256M tmpfs "${NETALERTX_API}"
@@ -82,19 +82,27 @@ configure_source() {
# tmpfs mounts configured with netalertx ownership and 775 permissions above
touch /app/log/nginx_error.log
echo " -> Empty log"|tee ${INSTALL_DIR}/log/app.log \
echo " -> Empty log"|tee ${INSTALL_DIR}/log/app.log \
${INSTALL_DIR}/log/app_front.log \
${INSTALL_DIR}/log/stdout.log
touch ${INSTALL_DIR}/log/stderr.log \
${INSTALL_DIR}/log/execution_queue.log
echo 0>${INSTALL_DIR}/log/db_is_locked.log
for f in ${INSTALL_DIR}/log/*.log; do
sudo chown netalertx:www-data $f
sudo chmod 664 $f
echo "" > $f
done
mkdir -p /app/log/plugins
sudo chown -R netalertx:www-data ${INSTALL_DIR}
killall python &>/dev/null
sleep 1
while `ps ax | grep -v grep | grep python3 > /dev/null`; do
killall python3 &>/dev/null
sleep 0.2
done
}
# configure_php: configure PHP-FPM and enable dev debug options
@@ -106,34 +114,24 @@ configure_php() {
# start_services: start crond, PHP-FPM, nginx and the application
start_services() {
echo "[4/4] Starting services..."
echo "[4/4] Starting services"
echo " -> Starting CronD (${SYSTEM_SERVICES_CROND}...)"
setsid nohup /services/start-crond.sh &>/dev/null &
echo " -> Starting PHP-FPM (${SYSTEM_SERVICES_PHP_FOLDER}...)"
setsid nohup /services/start-php-fpm.sh &>/dev/null &
# Wait for the previous nginx processes to exit and for the port to free up
tries=0
while ss -ltn | grep -q ":${PORT}[[:space:]]" && [ $tries -lt 10 ]; do
echo " -> Waiting for port ${PORT} to free..."
sleep 0.2
tries=$((tries+1))
done
chmod +x /entrypoint.sh
setsid bash /entrypoint.sh&
sleep 1
echo " -> Starting Nginx (${NETALERTX_FRONT}...)"
setsid nohup /services/start-nginx.sh &>/dev/null &
echo " -> Starting Backend (${NETALERTX_SERVER}...)"
setsid nohup /services/start-backend.sh >/dev/null 2>&1 &
sleep 2
}
echo "$(git rev-parse --short=8 HEAD)">/app/.VERSION
sudo chmod 755 /app/
echo "Development $(git rev-parse --short=8 HEAD)"| sudo tee /app/.VERSION
# Run the main function
main
# create a services readme file
echo "This folder is auto-generated by the container and devcontainer setup.sh script." > /services/README.md
echo "Any changes here will be lost on rebuild. To make permanent changes, edit files in .devcontainer or production filesystem and rebuild the container." >> /services/README.md
echo "Only make temporary/test changes in this folder, then perform a rebuild to reset." >> /services/README.md