Repository navigation
Expand file tree
/
Copy pathboot_v2.sh
More file actions
95 lines (80 loc) · 3.16 KB
/
Copy pathboot_v2.sh
File metadata and controls
95 lines (80 loc) · 3.16 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
#!/bin/bash
echo "🔴 === BOOT SCRIPT STARTED ==="
date
# 1. Define paths
NGINX_CONF="/home/site/wwwroot/default"
NGINX_BASE="/etc/nginx"
# 2. Nuclear Option: Clear ALL potential default configs
# This deletes the 'welcome page' configs commonly found in Nginx images
echo "--- Cleaning existing Nginx configs ---"
echo "Existing conf.d contents:"
ls -R $NGINX_BASE/conf.d
echo "Existing sites-enabled contents:"
ls -R $NGINX_BASE/sites-enabled
# Forcefully overwrite the default index.html so even if config fails, we don't see "Welcome to Nginx"
echo "--- Overwriting Default Index Page ---"
echo "<h1>PerfSimPhp Booting...</h1><p>If you see this, the Nginx config swap hasn't taken effect yet, but the boot script ran.</p>" > /usr/share/nginx/html/index.html
if [ $? -eq 0 ]; then
echo "✅ Successfully overwrote /usr/share/nginx/html/index.html"
else
echo "❌ FAILED to overwrite /usr/share/nginx/html/index.html"
fi
cat /usr/share/nginx/html/index.html
# Delete EVERYTHING in conf.d to ensure no stowaways
rm -rf $NGINX_BASE/conf.d/*
# Delete defaults in sites-*
rm -fv $NGINX_BASE/sites-enabled/default
rm -fv $NGINX_BASE/sites-available/default
# 3. Install OUR config
echo "--- Installing custom config ---"
if [ -f "$NGINX_CONF" ]; then
# Copy to sites-available (standard)
mkdir -p $NGINX_BASE/sites-available
cp "$NGINX_CONF" $NGINX_BASE/sites-available/default
# Link to sites-enabled (standard)
mkdir -p $NGINX_BASE/sites-enabled
ln -sf $NGINX_BASE/sites-available/default $NGINX_BASE/sites-enabled/default
echo "✅ Config installed to sites-enabled/default"
echo "--- Verified Content of sites-enabled/default ---"
cat $NGINX_BASE/sites-enabled/default
echo "-------------------------------------------------"
else
echo "❌ ERROR: /home/site/wwwroot/default file missing!"
exit 1
fi
# 4. Forensic: Inspect what is actually active
echo "--- Active Configuration Audit ---"
# Check if nginx.conf has a hardcoded include or server block
echo "Checking nginx.conf for server blocks:"
grep -n "server" $NGINX_BASE/nginx.conf
echo "Checking nginx.conf includes:"
grep -n "include" $NGINX_BASE/nginx.conf
echo "Checking nginx.conf root:"
grep -n "root" $NGINX_BASE/nginx.conf
# 5. Reload and Start
echo "--- Reloading Nginx ---"
# Kill any existing Nginx processes to ensure clean slate
pkill nginx
# Wait a moment
sleep 2
# Test config
nginx -t
# Start Nginx service (or reload if it survived)
service nginx start || service nginx reload
echo "--- Process Check (netstat) ---"
# Check what is listening
netstat -tulpn || ss -tulpn
echo "--- Internal Connectivity Check ---"
curl -I http://localhost:8080 || echo "Curl to 8080 failed"
curl -I http://localhost:80 || echo "Curl to 80 failed"
echo "--- Starting PHP-FPM ---"
# Start self-probe in background BEFORE php-fpm (which blocks)
# This generates external traffic visible in Azure AppLens
SELF_PROBE_SCRIPT="/home/site/wwwroot/self-probe.sh"
if [ -f "$SELF_PROBE_SCRIPT" ]; then
chmod +x "$SELF_PROBE_SCRIPT"
echo "Starting self-probe background process..."
nohup "$SELF_PROBE_SCRIPT" >> /home/LogFiles/self-probe.log 2>&1 &
echo "Self-probe PID: $!"
fi
php-fpm -F