Skip to content

Commit 287454f

Browse files
committed
Add bind debugging
1 parent 601b037 commit 287454f

File tree

2 files changed

+159
-2
lines changed

2 files changed

+159
-2
lines changed

ext/standard/tests/dns/bind-start.sh

Lines changed: 158 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ NAMED_CONF="$SCRIPT_DIR/named.conf"
1010
PID_FILE="$ZONES_DIR/named.pid"
1111
LOG_FILE="$SCRIPT_DIR/named.log"
1212

13+
# Debug: show current user and permissions
14+
echo "Debug: Current user: $(whoami)"
15+
echo "Debug: Current UID: $(id -u)"
16+
echo "Debug: Script dir: $SCRIPT_DIR"
17+
echo "Debug: Zones dir: $ZONES_DIR"
18+
1319
# Default mode: background
1420
FOREGROUND=false
1521
if [[ "${1:-}" == "-f" ]]; then
@@ -30,11 +36,82 @@ fi
3036

3137
# Generate named.conf from template
3238
echo "Generating $NAMED_CONF from $NAMED_CONF_TEMPLATE"
39+
40+
# Check if 127.0.0.1 is available and decide on listen address
41+
echo "Debug: Testing network connectivity for BIND address selection..."
42+
43+
IPV4_OK=false
44+
IPV6_OK=false
45+
46+
# Test IPv4 connectivity
47+
if ping -c 1 127.0.0.1 >/dev/null 2>&1; then
48+
IPV4_OK=true
49+
echo "Debug: IPv4 (127.0.0.1) is reachable"
50+
else
51+
echo "Debug: IPv4 (127.0.0.1) is NOT reachable"
52+
fi
53+
54+
# Test IPv6 connectivity
55+
if command -v ping6 >/dev/null 2>&1; then
56+
if ping6 -c 1 ::1 >/dev/null 2>&1; then
57+
IPV6_OK=true
58+
echo "Debug: IPv6 (::1) is reachable"
59+
fi
60+
else
61+
if ping -6 -c 1 ::1 >/dev/null 2>&1; then
62+
IPV6_OK=true
63+
echo "Debug: IPv6 (::1) is reachable via ping -6"
64+
fi
65+
fi
66+
67+
if ! $IPV6_OK; then
68+
echo "Debug: IPv6 (::1) is NOT reachable"
69+
fi
70+
71+
# Choose the listen address
72+
if $IPV4_OK; then
73+
LISTEN_ADDRESS="127.0.0.1"
74+
echo "Debug: Using IPv4 (127.0.0.1) for BIND"
75+
elif $IPV6_OK; then
76+
LISTEN_ADDRESS="::1"
77+
echo "Debug: Using IPv6 (::1) for BIND"
78+
else
79+
echo "Debug: Neither 127.0.0.1 nor ::1 is available!"
80+
echo "Debug: Falling back to 127.0.0.1 anyway"
81+
LISTEN_ADDRESS="127.0.0.1"
82+
fi
83+
3384
sed -e "s|@ZONES_DIR@|$ZONES_DIR|g" \
3485
-e "s|@PID_FILE@|$PID_FILE|g" \
3586
-e "s|@SCRIPT_DIR@|$SCRIPT_DIR|g" \
87+
-e "s|@LISTEN_ADDRESS@|$LISTEN_ADDRESS|g" \
3688
"$NAMED_CONF_TEMPLATE" > "$NAMED_CONF"
3789

90+
# Ensure the generated config file is readable
91+
chmod 644 "$NAMED_CONF"
92+
93+
# Debug: Check if the file is actually readable
94+
echo "Debug: Testing config file readability:"
95+
if [[ -r "$NAMED_CONF" ]]; then
96+
echo "Debug: Config file is readable"
97+
else
98+
echo "Debug: Config file is NOT readable"
99+
ls -la "$NAMED_CONF"
100+
exit 1
101+
fi
102+
103+
if [[ -f /etc/apparmor.d/usr.sbin.named ]]; then
104+
echo "Debug: AppArmor profile detected, setting to complain mode..."
105+
aa-complain /usr/sbin/named || echo "Failed to set AppArmor to complain mode"
106+
elif [ -d /etc/apparmor.d/ ]; then
107+
ls /etc/apparmor.d/
108+
else
109+
echo "No apparmor.d"
110+
fi
111+
112+
echo "Debug: Generated named.conf contents:"
113+
cat "$NAMED_CONF"
114+
38115
# Clean up any leftover journal or PID files
39116
rm -f "$ZONES_DIR"/*.jnl "$PID_FILE"
40117

@@ -43,10 +120,87 @@ echo "Starting BIND from $SCRIPT_DIR"
43120

44121
if $FOREGROUND; then
45122
echo "(running in foreground)"
123+
echo "Debug: About to exec: named -c $NAMED_CONF -p 53 -u $(whoami) -g -d 1"
46124
exec named -c "$NAMED_CONF" -p 53 -u "$(whoami)" -g -d 1
47125
else
48126
echo "(running in background)"
49-
named -c "$NAMED_CONF" -p 53 -u "$(whoami)"
127+
echo "Debug: About to run: named -c $NAMED_CONF -p 53 -u $(whoami)"
128+
129+
# Test configuration first
130+
echo "Debug: Testing BIND configuration..."
131+
if named-checkconf "$NAMED_CONF"; then
132+
echo "Debug: Configuration check passed"
133+
else
134+
echo "Debug: Configuration check failed"
135+
exit 1
136+
fi
137+
138+
# Check if zone files exist
139+
echo "Debug: Checking zone files..."
140+
if [[ -f "$ZONES_DIR/basic.dnstest.php.net.zone" ]]; then
141+
echo "Debug: Zone file exists"
142+
echo "Debug: Zone file contents:"
143+
cat "$ZONES_DIR/basic.dnstest.php.net.zone"
144+
else
145+
echo "Debug: Zone file missing: $ZONES_DIR/basic.dnstest.php.net.zone"
146+
ls -la "$ZONES_DIR/"
147+
exit 1
148+
fi
149+
150+
# Check IPv4/IPv6 configuration with fallbacks
151+
echo "Debug: Network configuration check:"
152+
echo "Debug: localhost resolution:"
153+
getent hosts localhost 2>/dev/null || echo "localhost not found in hosts"
154+
155+
echo "Debug: 127.0.0.1 resolution:"
156+
getent hosts 127.0.0.1 2>/dev/null || echo "127.0.0.1 not found"
157+
158+
echo "Debug: Available IP addresses:"
159+
if command -v ip >/dev/null 2>&1; then
160+
ip addr show lo 2>/dev/null || echo "Failed to show loopback interface with ip"
161+
else
162+
ifconfig lo 2>/dev/null || echo "Failed to show loopback interface with ifconfig"
163+
fi
164+
165+
echo "Debug: Can we reach 127.0.0.1?"
166+
ping -c 1 127.0.0.1 >/dev/null 2>&1 && echo "127.0.0.1 is reachable" || echo "127.0.0.1 is NOT reachable"
167+
168+
echo "Debug: Can we reach ::1?"
169+
if command -v ping6 >/dev/null 2>&1; then
170+
ping6 -c 1 ::1 >/dev/null 2>&1 && echo "::1 is reachable" || echo "::1 is NOT reachable"
171+
else
172+
ping -6 -c 1 ::1 >/dev/null 2>&1 && echo "::1 is reachable (via ping -6)" || echo "::1 is NOT reachable"
173+
fi
174+
175+
# Check what's listening on port 53
176+
echo "Debug: Processes listening on port 53:"
177+
if command -v ss >/dev/null 2>&1; then
178+
ss -tulpn 2>/dev/null | grep ':53' || echo "Debug: No processes found on port 53 (ss)"
179+
else
180+
netstat -tulpn 2>/dev/null | grep ':53' || echo "Debug: No processes found on port 53 (netstat)"
181+
fi
182+
183+
echo "Debug: systemd-resolved status:"
184+
systemctl is-active systemd-resolved 2>/dev/null || echo "systemd-resolved not active"
185+
186+
# Run named and capture both stdout and stderr separately
187+
echo "Debug: Starting named..."
188+
if named -c "$NAMED_CONF" -p 53 -u "$(whoami)" > "$LOG_FILE" 2>&1; then
189+
echo "Debug: named command succeeded"
190+
else
191+
NAMED_EXIT_CODE=$?
192+
echo "Debug: named command failed with exit code: $NAMED_EXIT_CODE"
193+
echo "Debug: Log file contents:"
194+
cat "$LOG_FILE" 2>/dev/null || echo "No log file found"
195+
196+
# Try to run named with more verbose output
197+
echo "Debug: Trying to run named in foreground for better error output:"
198+
named -c "$NAMED_CONF" -p 53 -u "$(whoami)" -g -d 1 || true
199+
200+
cat /var/log/syslog | grep apparmor | grep named
201+
202+
exit $NAMED_EXIT_CODE
203+
fi
50204

51205
# Wait for BIND to start with periodic checks
52206
MAX_WAIT=20 # Maximum wait time in attempts (20 * 0.5s = 10s)
@@ -76,7 +230,9 @@ else
76230
if [[ -f "$LOG_FILE" ]]; then
77231
echo "Last few lines from log:"
78232
tail -5 "$LOG_FILE"
233+
else
234+
echo "No log file found at $LOG_FILE"
79235
fi
80236

81237
exit 1
82-
fi
238+
fi

ext/standard/tests/dns/dns_get_record_basic.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ $result = dns_get_record($domain, DNS_A);
1010
var_dump($result);
1111
?>
1212
--EXPECTF--
13+
WRONG
1314
array(%d) {
1415
[0]=>
1516
array(%d) {

0 commit comments

Comments
 (0)