#!/usr/bin/env bash set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" source "$SCRIPT_DIR/../harness/helpers.sh" source "$SCRIPT_DIR/../harness/mock-nas.sh" require_root setup_test_env trap teardown_test_env EXIT # Start the mock NAS so rclone can connect via SFTP start_mock_nas # Generate a default config pointing at the mock NAS gen_config # Start warpgate and wait for full startup start_warpgate wait_for_log_line "Supervision active" 60 # Find smbd PID smbd_pid=$(pgrep -f "smbd.*--foreground") if [[ -z "$smbd_pid" ]]; then echo "FAIL: smbd not found" >&2 exit 1 fi # Kill smbd to trigger supervisor restart kill "$smbd_pid" # Wait for the supervisor to detect the exit and schedule a restart wait_for_log_line "Restarting smbd" 15 # Give the restart time to complete sleep 5 # Verify smbd is running again with a new PID new_smbd_pid=$(pgrep -f "smbd.*--foreground") if [[ -z "$new_smbd_pid" ]]; then echo "FAIL: smbd did not restart" >&2 exit 1 fi if [[ "$new_smbd_pid" -eq "$smbd_pid" ]]; then echo "FAIL: smbd PID did not change (expected new process)" >&2 exit 1 fi # Verify the log shows the correct restart message with backoff and counter assert_log_contains "Restarting smbd in 2s (1/3)" # Test SMB connectivity to the restarted smbd if command -v smbclient > /dev/null 2>&1; then smb_output=$(smbclient -L "127.0.0.1" -N 2>&1) || true if echo "$smb_output" | grep -qi "Sharename\|nas\|IPC"; then echo "INFO: SMB connectivity verified after restart" else echo "FAIL: smbclient could not list shares after smbd restart" >&2 echo " output: $smb_output" >&2 exit 1 fi else echo "INFO: smbclient not available, skipping SMB connectivity check" fi echo "PASS: $(basename "$0" .sh)"