#!/bin/bash # Create directories for nginx logs and pid file within $HOME mkdir -p $HOME/nginx_run $HOME/nginx_logs # Start Aim UI in the background echo "Starting Aim UI on port 43800..." # Run directly as aim_user aim up --host 0.0.0.0 --port 43800 --repo $HOME & AIM_UP_PID=$! # Start Aim Server in the background echo "Starting Aim Server on port 53800..." # Run directly as aim_user aim server --host 0.0.0.0 --port 53800 --repo $HOME & AIM_SERVER_PID=$! # Wait a few seconds for services to potentially start sleep 5 # Check if aim processes are still running if ! ps -p $AIM_UP_PID > /dev/null; then echo "Aim UI failed to start." >&2 # exit 1 # Optional: exit if a service fails fi if ! ps -p $AIM_SERVER_PID > /dev/null; then echo "Aim Server failed to start." >&2 # exit 1 # Optional: exit if a service fails fi echo "Aim services seem to be starting..." # Start nginx in the foreground using the system config file # Run directly as aim_user (no sudo needed) echo "Starting nginx..." nginx -c /etc/nginx/nginx.conf -g 'daemon off;' # If nginx exits, stop the background aim processes echo "Nginx exited. Stopping Aim services..." # Use kill without sudo, as processes are owned by aim_user kill $AIM_UP_PID $AIM_SERVER_PID # Wait for processes to ensure they are terminated wait $AIM_UP_PID $AIM_SERVER_PID echo "Exiting."