This commit is contained in:
2025-10-30 10:05:10 -07:00
commit 45af5f1e3d
3 changed files with 1154 additions and 0 deletions

350
checker.py Normal file
View File

@@ -0,0 +1,350 @@
import requests
import time
import logging
import sys
from typing import Dict, Any, Optional
from pprint import pprint
# Configure logging
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(levelname)s: %(message)s',
datefmt='%Y-%m-%d %H:%M:%S',
handlers=[
logging.StreamHandler(sys.stdout),
logging.FileHandler('connection_monitor.log')
]
)
logger = logging.getLogger(__name__)
class ConnectionMonitor:
def __init__(self,
qbittorrent_url: str = 'http://127.0.0.1:8080',
nomad_url: str = 'http://127.0.0.1:4646',
tracker_name: str = 'myanon'):
"""
Initialize connection monitoring with configurable parameters
"""
self.api_url = f'{qbittorrent_url}/api/v2/transfer/info'
self.qbittorrent_base_url = qbittorrent_url
self.nomad_url = nomad_url
self.tracker_name = tracker_name
# Tracking variables
self.consecutive_failures = 0
self.max_consecutive_failures = 2 # 10 minutes (30s * 20)
self.stability_wait_time = 1800 # 30 minutes
self.check_interval = 30 # seconds
# Authentication (update with your credentials)
self.qbittorrent_username = 'admin'
self.qbittorrent_password = 'adminpass'
def qbittorrent_login(self) -> requests.Session:
"""
Authenticate with qBittorrent
"""
try:
session = requests.Session()
login_url = f'{self.qbittorrent_base_url}/api/v2/auth/login'
login_data = {
'username': self.qbittorrent_username,
'password': self.qbittorrent_password
}
response = session.post(login_url, data=login_data)
response.raise_for_status()
logger.info("Successfully logged into qBittorrent")
return session
except requests.RequestException as e:
logger.error(f"qBittorrent login failed: {e}")
return None
def get_connection_status(self) -> Dict[str, Any]:
"""
Retrieve connection status from qBittorrent API
"""
try:
response = requests.get(self.api_url, timeout=10)
response.raise_for_status()
return response.json()
except requests.RequestException as e:
logger.error(f"API request failed: {e}")
return {}
def stop_tracker_torrents(self, session: requests.Session):
"""
Stop torrents matching specific tracker
"""
try:
# Get list of torrents
torrents_url = f'{self.qbittorrent_base_url}/api/v2/torrents/info'
torrents = session.get(torrents_url).json()
# Find and stop torrents with matching tracker
tracker_torrents = [
torrent['hash'] for torrent in torrents
if self.tracker_name.lower() in str(torrent).lower()
]
if tracker_torrents:
hashes_str = '|'.join(tracker_torrents)
pprint(hashes_str)
pause_url = f'{self.qbittorrent_base_url}/api/v2/torrents/stop'
response = session.post(pause_url, data={'hashes': hashes_str})
response.raise_for_status()
logger.info(f"Stopped {len(tracker_torrents)} torrents for tracker {self.tracker_name}")
else:
logger.info(f"No torrents found for tracker {self.tracker_name}")
except requests.RequestException as e:
logger.error(f"Failed to stop torrents: {e}")
return False
except Exception as e:
logger.error(f"Unexpected error stopping torrents: {e}")
return False
return True
def restart_nomad_task_via_allocation(self, job_id: str, task_name: str, namespace: str = "default", wait_time: int = 60) -> bool:
"""
Restart a specific task in a Nomad job by restarting just that task.
Args:
job_id: The ID of the job containing the task
task_name: The name of the task to restart
namespace: The namespace of the job (default: 'default')
wait_time: Seconds to wait after restart (default: 60)
Returns:
bool: True if restart succeeded, False otherwise
"""
headers = {}
if hasattr(self, 'token') and self.token:
headers['X-Nomad-Token'] = self.token
try:
# Get allocations for the job
allocs_url = f"{self.nomad_url}/v1/job/{job_id}/allocations"
params = {'namespace': namespace}
logger.info(f"Fetching allocations for job '{job_id}'...")
response = requests.get(allocs_url, headers=headers, params=params, timeout=10)
response.raise_for_status()
allocations = response.json()
# Find allocation containing the task
target_alloc = None
for alloc in allocations:
if alloc['ClientStatus'] == 'running':
task_states = alloc.get('TaskStates', {})
if task_name in task_states:
target_alloc = alloc
break
if not target_alloc:
logger.error(f"No running allocation found for task '{task_name}' in job '{job_id}'")
return False
# Restart just the specific task
alloc_id = target_alloc['ID']
restart_url = f"{self.nomad_url}/v1/client/allocation/{alloc_id}/restart"
payload = {"TaskName": task_name}
logger.info(f"Restarting task '{task_name}' in job '{job_id}'...")
response = requests.post(restart_url, headers=headers, params=params, json=payload, timeout=10)
if response.status_code in [200, 204]:
logger.info(f"Successfully restarted task '{task_name}' in job '{job_id}'")
time.sleep(wait_time)
return True
else:
logger.error(f"Failed: {response.status_code} - {response.text}")
return False
except Exception as e:
logger.error(f"Request failed: {e}")
return False
def restart_tracker_torrents(self, session: requests.Session):
"""
Restart torrents for specific tracker after stability period
"""
try:
# Get list of previously stopped torrents
torrents_url = f'{self.qbittorrent_base_url}/api/v2/torrents/info'
torrents = session.get(torrents_url).json()
# Find and resume torrents with matching tracker
tracker_torrents = [
torrent['hash'] for torrent in torrents
if (self.tracker_name.lower() in str(torrent).lower()
and torrent.get('state') == 'paused')
]
if tracker_torrents:
# resume_url = f'{self.qbittorrent_base_url}/api/v2/torrents/start'
# response = session.post(resume_url, data={'hashes': ','.join(tracker_torrents)})
# response.raise_for_status()
logger.info(f"Restarted {len(tracker_torrents)} torrents for tracker {self.tracker_name}")
else:
logger.info(f"No paused torrents found for tracker {self.tracker_name}")
except requests.RequestException as e:
logger.error(f"Failed to restart torrents: {e}")
def remediate_connection(self):
"""
Execute full remediation process
"""
logger.warning("Connection instability detected. Starting remediation...")
# Login to qBittorrent
qbt_session = self.qbittorrent_login()
if not qbt_session:
logger.error("Could not log in to qBittorrent. Aborting remediation.")
return False
# Stop torrents for specific tracker
self.stop_tracker_torrents(qbt_session)
sleep(30)
self.stop_tracker_torrents(qbt_session)
sleep(120) #wait 2 mins to make sure everything stopped
# Restart Nomad task
if not self.restart_nomad_task_via_allocation(
job_id="qbittorrent",
task_name="qbittorrent"
):
logger.error("Nomad task restart failed")
return False
# Wait for connection stability
logger.info(f"Waiting {self.stability_wait_time/60} minutes for connection stabilization...")
time.sleep(self.stability_wait_time)
# Verify connection
for _ in range(6): # 3 minutes of checks
status = self.get_connection_status()
is_connected = (
status.get('connection_status') == 'connected' and
status.get('dht_nodes', 0) > 0
)
if is_connected:
# Restart torrents
self.restart_tracker_torrents(qbt_session)
logger.info("Remediation completed successfully")
return True
time.sleep(30)
logger.error("Could not stabilize connection after remediation")
return False
def monitor_connection(self):
"""
Main connection monitoring loop
"""
logger.info("Starting connection monitoring...")
logger.info(f"Monitoring parameters:")
logger.info(f"Monitoring parameters:")
logger.info(f"- API URL: {self.api_url}")
logger.info(f"- Tracker: {self.tracker_name}")
logger.info(f"- Check Interval: {self.check_interval} seconds")
logger.info(f"- Max Consecutive Failures: {self.max_consecutive_failures}")
while True:
try:
# Get current connection status
status = self.get_connection_status()
# Check connection criteria
is_connected = (
status.get('connection_status') == 'xconnected' and
status.get('dht_nodes', 0) > 0
)
if is_connected:
# Reset failure counter if connected
self.consecutive_failures = 0
logger.debug(f"Connected. DHT Nodes: {status.get('dht_nodes', 0)}")
else:
# Increment failure counter
self.consecutive_failures += 1
logger.warning(f"Connection unstable. Failures: {self.consecutive_failures}")
# Check if remediation is needed
if self.consecutive_failures >= self.max_consecutive_failures:
logger.error("Persistent connection failure. Initiating remediation.")
remediation_result = self.remediate_connection()
# Reset failure counter based on remediation result
self.consecutive_failures = 0 if remediation_result else self.max_consecutive_failures
# Wait before next check
time.sleep(self.check_interval)
except Exception as e:
logger.error(f"Unexpected error in monitoring loop: {e}")
time.sleep(self.check_interval)
except KeyboardInterrupt:
logger.info("Connection monitoring stopped by user.")
break
def main():
"""
Main entry point for the connection monitoring script
"""
# Create monitor instance with optional custom parameters
monitor = ConnectionMonitor(
qbittorrent_url='http://sp.service.dc1.consul:8080', # Customize as needed
nomad_url='http://192.168.4.36:4646', # Customize as needed
tracker_name='https://t.myanonamouse.net/tracker.php/xxxx/announce' # Customize tracker name
)
try:
# Start connection monitoring
monitor.monitor_connection()
except Exception as e:
logger.critical(f"Critical error in main execution: {e}")
def debug_system_info():
"""
Log system and environment information for troubleshooting
"""
import platform
import socket
logger.info("System Diagnostic Information:")
logger.info(f"Python Version: {platform.python_version()}")
logger.info(f"Operating System: {platform.platform()}")
logger.info(f"Hostname: {socket.gethostname()}")
# Network connectivity check
try:
import requests
response = requests.get('https://www.google.com', timeout=5)
logger.info(f"Internet Connectivity: OK (Status Code: {response.status_code})")
except Exception as e:
logger.warning(f"Internet Connectivity Check Failed: {e}")
if __name__ == '__main__':
# Run system diagnostics before main script
debug_system_info()
# Configure additional logging
try:
# Attempt to set up more detailed logging
import logging
logging.getLogger('urllib3').setLevel(logging.WARNING)
logging.getLogger('requests').setLevel(logging.WARNING)
except Exception as e:
logger.error(f"Failed to configure additional logging: {e}")
# Run the main monitoring script
main()

559
connection_monitor.log Normal file
View File

@@ -0,0 +1,559 @@
2025-10-30 07:55:56,829 - INFO: Starting connection monitoring...
2025-10-30 07:57:04,170 - INFO: Connection monitoring stopped by user.
2025-10-30 07:58:59 - INFO: System Diagnostic Information:
2025-10-30 07:58:59 - INFO: Python Version: 3.13.3
2025-10-30 07:58:59 - INFO: Operating System: Linux-6.6.87.2-microsoft-standard-WSL2-x86_64-with-glibc2.41
2025-10-30 07:58:59 - INFO: Hostname: StuMini
2025-10-30 07:58:59 - DEBUG: Starting new HTTPS connection (1): www.google.com:443
2025-10-30 07:58:59 - DEBUG: https://www.google.com:443 "GET / HTTP/1.1" 200 None
2025-10-30 07:58:59 - INFO: Internet Connectivity: OK (Status Code: 200)
2025-10-30 07:58:59 - INFO: Starting connection monitoring...
2025-10-30 07:58:59 - INFO: Monitoring parameters:
2025-10-30 07:58:59 - INFO: - API URL: http://127.0.0.1:8080/api/v2/transfer/info
2025-10-30 07:58:59 - INFO: - Tracker: myanon
2025-10-30 07:58:59 - INFO: - Check Interval: 30 seconds
2025-10-30 07:58:59 - INFO: - Max Consecutive Failures: 20
2025-10-30 07:58:59 - DEBUG: Attempting to retrieve status from http://127.0.0.1:8080/api/v2/transfer/info
2025-10-30 07:59:09 - ERROR: API request failed: HTTPConnectionPool(host='127.0.0.1', port=8080): Max retries exceeded with url: /api/v2/transfer/info (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x74653ef00ad0>, 'Connection to 127.0.0.1 timed out. (connect timeout=10)'))
2025-10-30 07:59:09 - WARNING: Failed to retrieve connection status
2025-10-30 07:59:09 - DEBUG: Waiting 30 seconds before next check
2025-10-30 07:59:10 - INFO: Connection monitoring stopped by user.
2025-10-30 07:59:32 - INFO: System Diagnostic Information:
2025-10-30 07:59:32 - INFO: Python Version: 3.13.3
2025-10-30 07:59:32 - INFO: Operating System: Linux-6.6.87.2-microsoft-standard-WSL2-x86_64-with-glibc2.41
2025-10-30 07:59:32 - INFO: Hostname: StuMini
2025-10-30 07:59:32 - DEBUG: Starting new HTTPS connection (1): www.google.com:443
2025-10-30 07:59:32 - DEBUG: https://www.google.com:443 "GET / HTTP/1.1" 200 None
2025-10-30 07:59:32 - INFO: Internet Connectivity: OK (Status Code: 200)
2025-10-30 07:59:32 - INFO: Starting connection monitoring...
2025-10-30 07:59:32 - INFO: Monitoring parameters:
2025-10-30 07:59:32 - INFO: - API URL: http://sp.service.dc1.consul:8080/api/v2/transfer/info
2025-10-30 07:59:32 - INFO: - Tracker: myanon
2025-10-30 07:59:32 - INFO: - Check Interval: 30 seconds
2025-10-30 07:59:32 - INFO: - Max Consecutive Failures: 20
2025-10-30 07:59:32 - DEBUG: Attempting to retrieve status from http://sp.service.dc1.consul:8080/api/v2/transfer/info
2025-10-30 07:59:32 - DEBUG: Retrieved status: {'connection_status': 'connected', 'dht_nodes': 328, 'dl_info_data': 23875400556, 'dl_info_speed': 0, 'dl_rate_limit': 0, 'last_external_address_v4': '192.30.89.75', 'last_external_address_v6': '', 'up_info_data': 1791577174, 'up_info_speed': 576490, 'up_rate_limit': 0}
2025-10-30 07:59:32 - DEBUG: Current Status: Connected=True, DHT Nodes=328
2025-10-30 07:59:32 - DEBUG: Waiting 30 seconds before next check
2025-10-30 08:00:04 - DEBUG: Attempting to retrieve status from http://sp.service.dc1.consul:8080/api/v2/transfer/info
2025-10-30 08:00:04 - DEBUG: Retrieved status: {'connection_status': 'connected', 'dht_nodes': 328, 'dl_info_data': 23875400556, 'dl_info_speed': 0, 'dl_rate_limit': 0, 'last_external_address_v4': '192.30.89.75', 'last_external_address_v6': '', 'up_info_data': 1802582505, 'up_info_speed': 319887, 'up_rate_limit': 0}
2025-10-30 08:00:04 - DEBUG: Current Status: Connected=True, DHT Nodes=328
2025-10-30 08:00:04 - DEBUG: Waiting 30 seconds before next check
2025-10-30 08:00:34 - DEBUG: Attempting to retrieve status from http://sp.service.dc1.consul:8080/api/v2/transfer/info
2025-10-30 08:00:34 - DEBUG: Retrieved status: {'connection_status': 'connected', 'dht_nodes': 328, 'dl_info_data': 23875400556, 'dl_info_speed': 0, 'dl_rate_limit': 0, 'last_external_address_v4': '192.30.89.75', 'last_external_address_v6': '', 'up_info_data': 1810337532, 'up_info_speed': 223998, 'up_rate_limit': 0}
2025-10-30 08:00:34 - DEBUG: Current Status: Connected=True, DHT Nodes=328
2025-10-30 08:00:34 - DEBUG: Waiting 30 seconds before next check
2025-10-30 08:01:07 - DEBUG: Attempting to retrieve status from http://sp.service.dc1.consul:8080/api/v2/transfer/info
2025-10-30 08:01:07 - DEBUG: Retrieved status: {'connection_status': 'connected', 'dht_nodes': 328, 'dl_info_data': 23875400556, 'dl_info_speed': 0, 'dl_rate_limit': 0, 'last_external_address_v4': '192.30.89.75', 'last_external_address_v6': '', 'up_info_data': 1817910490, 'up_info_speed': 505960, 'up_rate_limit': 0}
2025-10-30 08:01:07 - DEBUG: Current Status: Connected=True, DHT Nodes=328
2025-10-30 08:01:07 - DEBUG: Waiting 30 seconds before next check
2025-10-30 08:01:13 - INFO: Connection monitoring stopped by user.
2025-10-30 08:13:47 - INFO: System Diagnostic Information:
2025-10-30 08:13:47 - INFO: Python Version: 3.13.3
2025-10-30 08:13:47 - INFO: Operating System: Linux-6.6.87.2-microsoft-standard-WSL2-x86_64-with-glibc2.41
2025-10-30 08:13:47 - INFO: Hostname: StuMini
2025-10-30 08:13:47 - DEBUG: Starting new HTTPS connection (1): www.google.com:443
2025-10-30 08:13:47 - DEBUG: https://www.google.com:443 "GET / HTTP/1.1" 200 None
2025-10-30 08:13:47 - INFO: Internet Connectivity: OK (Status Code: 200)
2025-10-30 08:13:47 - INFO: Starting connection monitoring...
2025-10-30 08:13:47 - INFO: Monitoring parameters:
2025-10-30 08:13:47 - INFO: Monitoring parameters:
2025-10-30 08:13:47 - INFO: - API URL: http://sp.service.dc1.consul:8080/api/v2/transfer/info
2025-10-30 08:13:47 - INFO: - Tracker: myanon
2025-10-30 08:13:47 - INFO: - Check Interval: 30 seconds
2025-10-30 08:13:47 - INFO: - Max Consecutive Failures: 20
2025-10-30 08:13:48 - DEBUG: Connected. DHT Nodes: 328
2025-10-30 08:14:09 - INFO: Connection monitoring stopped by user.
2025-10-30 08:16:15 - INFO: System Diagnostic Information:
2025-10-30 08:16:15 - INFO: Python Version: 3.13.3
2025-10-30 08:16:15 - INFO: Operating System: Linux-6.6.87.2-microsoft-standard-WSL2-x86_64-with-glibc2.41
2025-10-30 08:16:15 - INFO: Hostname: StuMini
2025-10-30 08:16:15 - DEBUG: Starting new HTTPS connection (1): www.google.com:443
2025-10-30 08:16:15 - DEBUG: https://www.google.com:443 "GET / HTTP/1.1" 200 None
2025-10-30 08:16:15 - INFO: Internet Connectivity: OK (Status Code: 200)
2025-10-30 08:16:15 - INFO: Starting connection monitoring...
2025-10-30 08:16:15 - INFO: Monitoring parameters:
2025-10-30 08:16:15 - INFO: Monitoring parameters:
2025-10-30 08:16:15 - INFO: - API URL: http://sp.service.dc1.consul:8080/api/v2/transfer/info
2025-10-30 08:16:15 - INFO: - Tracker: https://t.myanonamouse.net/tracker.php/VPRYYAL-WpTwnr9G9aIN6044YVZ7x8Ao/announce
2025-10-30 08:16:15 - INFO: - Check Interval: 30 seconds
2025-10-30 08:16:15 - INFO: - Max Consecutive Failures: 20
2025-10-30 08:16:16 - DEBUG: Connected. DHT Nodes: 328
2025-10-30 08:16:48 - DEBUG: Connected. DHT Nodes: 328
2025-10-30 08:17:20 - DEBUG: Connected. DHT Nodes: 328
2025-10-30 08:17:50 - DEBUG: Connected. DHT Nodes: 328
2025-10-30 08:18:23 - DEBUG: Connected. DHT Nodes: 328
2025-10-30 08:18:55 - DEBUG: Connected. DHT Nodes: 328
2025-10-30 08:19:28 - DEBUG: Connected. DHT Nodes: 328
2025-10-30 08:20:00 - DEBUG: Connected. DHT Nodes: 328
2025-10-30 08:20:32 - DEBUG: Connected. DHT Nodes: 328
2025-10-30 08:21:04 - DEBUG: Connected. DHT Nodes: 328
2025-10-30 08:21:37 - DEBUG: Connected. DHT Nodes: 328
2025-10-30 08:22:09 - DEBUG: Connected. DHT Nodes: 328
2025-10-30 08:22:41 - DEBUG: Connected. DHT Nodes: 328
2025-10-30 08:23:13 - DEBUG: Connected. DHT Nodes: 328
2025-10-30 08:23:45 - DEBUG: Connected. DHT Nodes: 328
2025-10-30 08:24:17 - DEBUG: Connected. DHT Nodes: 328
2025-10-30 08:24:50 - DEBUG: Connected. DHT Nodes: 328
2025-10-30 08:25:20 - DEBUG: Connected. DHT Nodes: 328
2025-10-30 08:25:52 - DEBUG: Connected. DHT Nodes: 328
2025-10-30 08:26:24 - DEBUG: Connected. DHT Nodes: 328
2025-10-30 08:26:56 - DEBUG: Connected. DHT Nodes: 328
2025-10-30 08:27:28 - DEBUG: Connected. DHT Nodes: 328
2025-10-30 08:28:00 - DEBUG: Connected. DHT Nodes: 328
2025-10-30 08:28:33 - DEBUG: Connected. DHT Nodes: 328
2025-10-30 08:29:05 - DEBUG: Connected. DHT Nodes: 328
2025-10-30 08:29:37 - DEBUG: Connected. DHT Nodes: 328
2025-10-30 08:30:09 - DEBUG: Connected. DHT Nodes: 328
2025-10-30 08:30:42 - DEBUG: Connected. DHT Nodes: 328
2025-10-30 08:31:14 - DEBUG: Connected. DHT Nodes: 333
2025-10-30 08:31:46 - DEBUG: Connected. DHT Nodes: 333
2025-10-30 08:32:18 - DEBUG: Connected. DHT Nodes: 334
2025-10-30 08:32:51 - DEBUG: Connected. DHT Nodes: 334
2025-10-30 08:33:21 - DEBUG: Connected. DHT Nodes: 341
2025-10-30 08:33:53 - DEBUG: Connected. DHT Nodes: 345
2025-10-30 08:34:25 - DEBUG: Connected. DHT Nodes: 346
2025-10-30 08:34:58 - DEBUG: Connected. DHT Nodes: 347
2025-10-30 08:35:30 - DEBUG: Connected. DHT Nodes: 352
2025-10-30 08:36:03 - DEBUG: Connected. DHT Nodes: 358
2025-10-30 08:36:35 - DEBUG: Connected. DHT Nodes: 359
2025-10-30 08:37:08 - DEBUG: Connected. DHT Nodes: 359
2025-10-30 08:37:40 - DEBUG: Connected. DHT Nodes: 359
2025-10-30 08:38:13 - DEBUG: Connected. DHT Nodes: 359
2025-10-30 08:38:45 - DEBUG: Connected. DHT Nodes: 360
2025-10-30 08:39:18 - DEBUG: Connected. DHT Nodes: 360
2025-10-30 08:39:51 - DEBUG: Connected. DHT Nodes: 360
2025-10-30 08:40:23 - DEBUG: Connected. DHT Nodes: 360
2025-10-30 08:40:53 - DEBUG: Connected. DHT Nodes: 360
2025-10-30 08:41:26 - DEBUG: Connected. DHT Nodes: 360
2025-10-30 08:41:59 - DEBUG: Connected. DHT Nodes: 360
2025-10-30 08:42:31 - DEBUG: Connected. DHT Nodes: 360
2025-10-30 08:43:03 - DEBUG: Connected. DHT Nodes: 360
2025-10-30 08:43:35 - DEBUG: Connected. DHT Nodes: 360
2025-10-30 08:44:07 - DEBUG: Connected. DHT Nodes: 360
2025-10-30 08:44:40 - DEBUG: Connected. DHT Nodes: 360
2025-10-30 08:45:12 - DEBUG: Connected. DHT Nodes: 360
2025-10-30 08:45:44 - DEBUG: Connected. DHT Nodes: 360
2025-10-30 08:46:16 - DEBUG: Connected. DHT Nodes: 360
2025-10-30 08:46:49 - DEBUG: Connected. DHT Nodes: 360
2025-10-30 08:47:21 - DEBUG: Connected. DHT Nodes: 360
2025-10-30 08:47:53 - DEBUG: Connected. DHT Nodes: 360
2025-10-30 08:48:26 - DEBUG: Connected. DHT Nodes: 360
2025-10-30 08:48:56 - DEBUG: Connected. DHT Nodes: 360
2025-10-30 08:49:28 - DEBUG: Connected. DHT Nodes: 360
2025-10-30 08:50:00 - DEBUG: Connected. DHT Nodes: 362
2025-10-30 08:50:33 - DEBUG: Connected. DHT Nodes: 363
2025-10-30 08:51:05 - DEBUG: Connected. DHT Nodes: 363
2025-10-30 08:51:38 - DEBUG: Connected. DHT Nodes: 363
2025-10-30 08:52:10 - DEBUG: Connected. DHT Nodes: 363
2025-10-30 08:52:43 - DEBUG: Connected. DHT Nodes: 363
2025-10-30 08:53:15 - DEBUG: Connected. DHT Nodes: 363
2025-10-30 08:53:48 - DEBUG: Connected. DHT Nodes: 364
2025-10-30 08:54:20 - DEBUG: Connected. DHT Nodes: 365
2025-10-30 08:54:53 - DEBUG: Connected. DHT Nodes: 365
2025-10-30 08:55:25 - DEBUG: Connected. DHT Nodes: 365
2025-10-30 08:55:58 - DEBUG: Connected. DHT Nodes: 365
2025-10-30 08:56:28 - DEBUG: Connected. DHT Nodes: 365
2025-10-30 08:57:01 - DEBUG: Connected. DHT Nodes: 365
2025-10-30 08:57:34 - DEBUG: Connected. DHT Nodes: 365
2025-10-30 08:58:07 - DEBUG: Connected. DHT Nodes: 365
2025-10-30 08:58:39 - DEBUG: Connected. DHT Nodes: 365
2025-10-30 08:59:12 - DEBUG: Connected. DHT Nodes: 365
2025-10-30 08:59:45 - DEBUG: Connected. DHT Nodes: 365
2025-10-30 08:59:55 - INFO: Connection monitoring stopped by user.
2025-10-30 09:12:10 - INFO: System Diagnostic Information:
2025-10-30 09:12:10 - INFO: Python Version: 3.13.3
2025-10-30 09:12:10 - INFO: Operating System: Linux-6.6.87.2-microsoft-standard-WSL2-x86_64-with-glibc2.41
2025-10-30 09:12:10 - INFO: Hostname: StuMini
2025-10-30 09:12:10 - DEBUG: Starting new HTTPS connection (1): www.google.com:443
2025-10-30 09:12:10 - DEBUG: https://www.google.com:443 "GET / HTTP/1.1" 200 None
2025-10-30 09:12:10 - INFO: Internet Connectivity: OK (Status Code: 200)
2025-10-30 09:12:10 - INFO: Starting connection monitoring...
2025-10-30 09:12:10 - INFO: Monitoring parameters:
2025-10-30 09:12:10 - INFO: Monitoring parameters:
2025-10-30 09:12:10 - INFO: - API URL: http://sp.service.dc1.consul:8080/api/v2/transfer/info
2025-10-30 09:12:10 - INFO: - Tracker: https://t.myanonamouse.net/tracker.php/VPRYYAL-WpTwnr9G9aIN6044YVZ7x8Ao/announce
2025-10-30 09:12:10 - INFO: - Check Interval: 30 seconds
2025-10-30 09:12:10 - INFO: - Max Consecutive Failures: 20
2025-10-30 09:12:10 - DEBUG: Connected. DHT Nodes: 303
2025-10-30 09:12:42 - DEBUG: Connected. DHT Nodes: 304
2025-10-30 09:13:12 - DEBUG: Connected. DHT Nodes: 304
2025-10-30 09:13:44 - DEBUG: Connected. DHT Nodes: 304
2025-10-30 09:14:16 - DEBUG: Connected. DHT Nodes: 304
2025-10-30 09:14:48 - DEBUG: Connected. DHT Nodes: 304
2025-10-30 09:15:20 - DEBUG: Connected. DHT Nodes: 304
2025-10-30 09:15:52 - DEBUG: Connected. DHT Nodes: 304
2025-10-30 09:16:24 - DEBUG: Connected. DHT Nodes: 304
2025-10-30 09:16:56 - DEBUG: Connected. DHT Nodes: 304
2025-10-30 09:17:28 - DEBUG: Connected. DHT Nodes: 304
2025-10-30 09:18:00 - DEBUG: Connected. DHT Nodes: 304
2025-10-30 09:18:32 - DEBUG: Connected. DHT Nodes: 304
2025-10-30 09:19:04 - DEBUG: Connected. DHT Nodes: 316
2025-10-30 09:19:37 - DEBUG: Connected. DHT Nodes: 318
2025-10-30 09:20:09 - ERROR: API request failed: HTTPConnectionPool(host='sp.service.dc1.consul', port=8080): Max retries exceeded with url: /api/v2/transfer/info (Caused by NameResolutionError("<urllib3.connection.HTTPConnection object at 0x7e0d9da0b130>: Failed to resolve 'sp.service.dc1.consul' ([Errno -2] Name or service not known)"))
2025-10-30 09:20:09 - WARNING: Connection unstable. Failures: 1
2025-10-30 09:20:39 - ERROR: API request failed: HTTPConnectionPool(host='sp.service.dc1.consul', port=8080): Max retries exceeded with url: /api/v2/transfer/info (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7e0d9da0af10>: Failed to establish a new connection: [Errno 111] Connection refused'))
2025-10-30 09:20:39 - WARNING: Connection unstable. Failures: 2
2025-10-30 09:20:59 - INFO: Connection monitoring stopped by user.
2025-10-30 09:21:42 - INFO: System Diagnostic Information:
2025-10-30 09:21:42 - INFO: Python Version: 3.13.3
2025-10-30 09:21:42 - INFO: Operating System: Linux-6.6.87.2-microsoft-standard-WSL2-x86_64-with-glibc2.41
2025-10-30 09:21:42 - INFO: Hostname: StuMini
2025-10-30 09:21:42 - DEBUG: Starting new HTTPS connection (1): www.google.com:443
2025-10-30 09:21:42 - DEBUG: https://www.google.com:443 "GET / HTTP/1.1" 200 None
2025-10-30 09:21:42 - INFO: Internet Connectivity: OK (Status Code: 200)
2025-10-30 09:21:42 - INFO: Starting connection monitoring...
2025-10-30 09:21:42 - INFO: Monitoring parameters:
2025-10-30 09:21:42 - INFO: Monitoring parameters:
2025-10-30 09:21:42 - INFO: - API URL: http://sp.service.dc1.consul:8080/api/v2/transfer/info
2025-10-30 09:21:42 - INFO: - Tracker: https://t.myanonamouse.net/tracker.php/VPRYYAL-WpTwnr9G9aIN6044YVZ7x8Ao/announce
2025-10-30 09:21:42 - INFO: - Check Interval: 30 seconds
2025-10-30 09:21:42 - INFO: - Max Consecutive Failures: 1
2025-10-30 09:21:42 - ERROR: API request failed: HTTPConnectionPool(host='sp.service.dc1.consul', port=8080): Max retries exceeded with url: /api/v2/transfer/info (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7058c94d4ad0>: Failed to establish a new connection: [Errno 111] Connection refused'))
2025-10-30 09:21:42 - WARNING: Connection unstable. Failures: 1
2025-10-30 09:21:42 - ERROR: Persistent connection failure. Initiating remediation.
2025-10-30 09:21:42 - WARNING: Connection instability detected. Starting remediation...
2025-10-30 09:21:42 - ERROR: qBittorrent login failed: HTTPConnectionPool(host='sp.service.dc1.consul', port=8080): Max retries exceeded with url: /api/v2/auth/login (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7058c94cc410>: Failed to establish a new connection: [Errno 111] Connection refused'))
2025-10-30 09:21:42 - ERROR: Could not log in to qBittorrent. Aborting remediation.
2025-10-30 09:21:54 - INFO: Connection monitoring stopped by user.
2025-10-30 09:21:55 - INFO: System Diagnostic Information:
2025-10-30 09:21:55 - INFO: Python Version: 3.13.3
2025-10-30 09:21:55 - INFO: Operating System: Linux-6.6.87.2-microsoft-standard-WSL2-x86_64-with-glibc2.41
2025-10-30 09:21:55 - INFO: Hostname: StuMini
2025-10-30 09:21:55 - DEBUG: Starting new HTTPS connection (1): www.google.com:443
2025-10-30 09:21:55 - DEBUG: https://www.google.com:443 "GET / HTTP/1.1" 200 None
2025-10-30 09:21:55 - INFO: Internet Connectivity: OK (Status Code: 200)
2025-10-30 09:21:55 - INFO: Starting connection monitoring...
2025-10-30 09:21:55 - INFO: Monitoring parameters:
2025-10-30 09:21:55 - INFO: Monitoring parameters:
2025-10-30 09:21:55 - INFO: - API URL: http://sp.service.dc1.consul:8080/api/v2/transfer/info
2025-10-30 09:21:55 - INFO: - Tracker: https://t.myanonamouse.net/tracker.php/VPRYYAL-WpTwnr9G9aIN6044YVZ7x8Ao/announce
2025-10-30 09:21:55 - INFO: - Check Interval: 30 seconds
2025-10-30 09:21:55 - INFO: - Max Consecutive Failures: 1
2025-10-30 09:21:55 - ERROR: API request failed: HTTPConnectionPool(host='sp.service.dc1.consul', port=8080): Max retries exceeded with url: /api/v2/transfer/info (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x775c2a0ccad0>: Failed to establish a new connection: [Errno 111] Connection refused'))
2025-10-30 09:21:55 - WARNING: Connection unstable. Failures: 1
2025-10-30 09:21:55 - ERROR: Persistent connection failure. Initiating remediation.
2025-10-30 09:21:55 - WARNING: Connection instability detected. Starting remediation...
2025-10-30 09:21:55 - ERROR: qBittorrent login failed: HTTPConnectionPool(host='sp.service.dc1.consul', port=8080): Max retries exceeded with url: /api/v2/auth/login (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x775c2a0c8410>: Failed to establish a new connection: [Errno 111] Connection refused'))
2025-10-30 09:21:55 - ERROR: Could not log in to qBittorrent. Aborting remediation.
2025-10-30 09:22:18 - INFO: Connection monitoring stopped by user.
2025-10-30 09:22:18 - INFO: System Diagnostic Information:
2025-10-30 09:22:18 - INFO: Python Version: 3.13.3
2025-10-30 09:22:18 - INFO: Operating System: Linux-6.6.87.2-microsoft-standard-WSL2-x86_64-with-glibc2.41
2025-10-30 09:22:18 - INFO: Hostname: StuMini
2025-10-30 09:22:18 - DEBUG: Starting new HTTPS connection (1): www.google.com:443
2025-10-30 09:22:18 - DEBUG: https://www.google.com:443 "GET / HTTP/1.1" 200 None
2025-10-30 09:22:18 - INFO: Internet Connectivity: OK (Status Code: 200)
2025-10-30 09:22:18 - INFO: Starting connection monitoring...
2025-10-30 09:22:18 - INFO: Monitoring parameters:
2025-10-30 09:22:18 - INFO: Monitoring parameters:
2025-10-30 09:22:18 - INFO: - API URL: http://sp.service.dc1.consul:8080/api/v2/transfer/info
2025-10-30 09:22:18 - INFO: - Tracker: https://t.myanonamouse.net/tracker.php/VPRYYAL-WpTwnr9G9aIN6044YVZ7x8Ao/announce
2025-10-30 09:22:18 - INFO: - Check Interval: 30 seconds
2025-10-30 09:22:18 - INFO: - Max Consecutive Failures: 1
2025-10-30 09:22:18 - ERROR: API request failed: HTTPConnectionPool(host='sp.service.dc1.consul', port=8080): Max retries exceeded with url: /api/v2/transfer/info (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7c7bb23f0ad0>: Failed to establish a new connection: [Errno 111] Connection refused'))
2025-10-30 09:22:18 - WARNING: Connection unstable. Failures: 1
2025-10-30 09:22:18 - ERROR: Persistent connection failure. Initiating remediation.
2025-10-30 09:22:18 - WARNING: Connection instability detected. Starting remediation...
2025-10-30 09:22:18 - ERROR: qBittorrent login failed: HTTPConnectionPool(host='sp.service.dc1.consul', port=8080): Max retries exceeded with url: /api/v2/auth/login (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7c7bb23ec410>: Failed to establish a new connection: [Errno 111] Connection refused'))
2025-10-30 09:22:18 - ERROR: Could not log in to qBittorrent. Aborting remediation.
2025-10-30 09:22:30 - INFO: Connection monitoring stopped by user.
2025-10-30 09:22:31 - INFO: System Diagnostic Information:
2025-10-30 09:22:31 - INFO: Python Version: 3.13.3
2025-10-30 09:22:31 - INFO: Operating System: Linux-6.6.87.2-microsoft-standard-WSL2-x86_64-with-glibc2.41
2025-10-30 09:22:31 - INFO: Hostname: StuMini
2025-10-30 09:22:31 - DEBUG: Starting new HTTPS connection (1): www.google.com:443
2025-10-30 09:22:31 - DEBUG: https://www.google.com:443 "GET / HTTP/1.1" 200 None
2025-10-30 09:22:31 - INFO: Internet Connectivity: OK (Status Code: 200)
2025-10-30 09:22:31 - INFO: Starting connection monitoring...
2025-10-30 09:22:31 - INFO: Monitoring parameters:
2025-10-30 09:22:31 - INFO: Monitoring parameters:
2025-10-30 09:22:31 - INFO: - API URL: http://sp.service.dc1.consul:8080/api/v2/transfer/info
2025-10-30 09:22:31 - INFO: - Tracker: https://t.myanonamouse.net/tracker.php/VPRYYAL-WpTwnr9G9aIN6044YVZ7x8Ao/announce
2025-10-30 09:22:31 - INFO: - Check Interval: 30 seconds
2025-10-30 09:22:31 - INFO: - Max Consecutive Failures: 1
2025-10-30 09:22:31 - ERROR: API request failed: HTTPConnectionPool(host='sp.service.dc1.consul', port=8080): Max retries exceeded with url: /api/v2/transfer/info (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7e11bce30ad0>: Failed to establish a new connection: [Errno 111] Connection refused'))
2025-10-30 09:22:31 - WARNING: Connection unstable. Failures: 1
2025-10-30 09:22:31 - ERROR: Persistent connection failure. Initiating remediation.
2025-10-30 09:22:31 - WARNING: Connection instability detected. Starting remediation...
2025-10-30 09:22:31 - ERROR: qBittorrent login failed: HTTPConnectionPool(host='sp.service.dc1.consul', port=8080): Max retries exceeded with url: /api/v2/auth/login (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7e11bce28410>: Failed to establish a new connection: [Errno 111] Connection refused'))
2025-10-30 09:22:31 - ERROR: Could not log in to qBittorrent. Aborting remediation.
2025-10-30 09:22:33 - INFO: Connection monitoring stopped by user.
2025-10-30 09:22:34 - INFO: System Diagnostic Information:
2025-10-30 09:22:34 - INFO: Python Version: 3.13.3
2025-10-30 09:22:34 - INFO: Operating System: Linux-6.6.87.2-microsoft-standard-WSL2-x86_64-with-glibc2.41
2025-10-30 09:22:34 - INFO: Hostname: StuMini
2025-10-30 09:22:34 - DEBUG: Starting new HTTPS connection (1): www.google.com:443
2025-10-30 09:22:34 - DEBUG: https://www.google.com:443 "GET / HTTP/1.1" 200 None
2025-10-30 09:22:34 - INFO: Internet Connectivity: OK (Status Code: 200)
2025-10-30 09:22:34 - INFO: Starting connection monitoring...
2025-10-30 09:22:34 - INFO: Monitoring parameters:
2025-10-30 09:22:34 - INFO: Monitoring parameters:
2025-10-30 09:22:34 - INFO: - API URL: http://sp.service.dc1.consul:8080/api/v2/transfer/info
2025-10-30 09:22:34 - INFO: - Tracker: https://t.myanonamouse.net/tracker.php/VPRYYAL-WpTwnr9G9aIN6044YVZ7x8Ao/announce
2025-10-30 09:22:34 - INFO: - Check Interval: 30 seconds
2025-10-30 09:22:34 - INFO: - Max Consecutive Failures: 1
2025-10-30 09:22:34 - ERROR: API request failed: HTTPConnectionPool(host='sp.service.dc1.consul', port=8080): Max retries exceeded with url: /api/v2/transfer/info (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x78685e920ad0>: Failed to establish a new connection: [Errno 111] Connection refused'))
2025-10-30 09:22:34 - WARNING: Connection unstable. Failures: 1
2025-10-30 09:22:34 - ERROR: Persistent connection failure. Initiating remediation.
2025-10-30 09:22:34 - WARNING: Connection instability detected. Starting remediation...
2025-10-30 09:22:34 - ERROR: qBittorrent login failed: HTTPConnectionPool(host='sp.service.dc1.consul', port=8080): Max retries exceeded with url: /api/v2/auth/login (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x78685e91c410>: Failed to establish a new connection: [Errno 111] Connection refused'))
2025-10-30 09:22:34 - ERROR: Could not log in to qBittorrent. Aborting remediation.
2025-10-30 09:22:37 - INFO: Connection monitoring stopped by user.
2025-10-30 09:22:37 - INFO: System Diagnostic Information:
2025-10-30 09:22:37 - INFO: Python Version: 3.13.3
2025-10-30 09:22:37 - INFO: Operating System: Linux-6.6.87.2-microsoft-standard-WSL2-x86_64-with-glibc2.41
2025-10-30 09:22:37 - INFO: Hostname: StuMini
2025-10-30 09:22:37 - DEBUG: Starting new HTTPS connection (1): www.google.com:443
2025-10-30 09:22:37 - DEBUG: https://www.google.com:443 "GET / HTTP/1.1" 200 None
2025-10-30 09:22:37 - INFO: Internet Connectivity: OK (Status Code: 200)
2025-10-30 09:22:37 - INFO: Starting connection monitoring...
2025-10-30 09:22:37 - INFO: Monitoring parameters:
2025-10-30 09:22:37 - INFO: Monitoring parameters:
2025-10-30 09:22:37 - INFO: - API URL: http://sp.service.dc1.consul:8080/api/v2/transfer/info
2025-10-30 09:22:37 - INFO: - Tracker: https://t.myanonamouse.net/tracker.php/VPRYYAL-WpTwnr9G9aIN6044YVZ7x8Ao/announce
2025-10-30 09:22:37 - INFO: - Check Interval: 30 seconds
2025-10-30 09:22:37 - INFO: - Max Consecutive Failures: 1
2025-10-30 09:22:37 - ERROR: API request failed: HTTPConnectionPool(host='sp.service.dc1.consul', port=8080): Max retries exceeded with url: /api/v2/transfer/info (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x751372de0ad0>: Failed to establish a new connection: [Errno 111] Connection refused'))
2025-10-30 09:22:37 - WARNING: Connection unstable. Failures: 1
2025-10-30 09:22:37 - ERROR: Persistent connection failure. Initiating remediation.
2025-10-30 09:22:37 - WARNING: Connection instability detected. Starting remediation...
2025-10-30 09:22:37 - ERROR: qBittorrent login failed: HTTPConnectionPool(host='sp.service.dc1.consul', port=8080): Max retries exceeded with url: /api/v2/auth/login (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x751372ddc410>: Failed to establish a new connection: [Errno 111] Connection refused'))
2025-10-30 09:22:37 - ERROR: Could not log in to qBittorrent. Aborting remediation.
2025-10-30 09:22:39 - INFO: Connection monitoring stopped by user.
2025-10-30 09:22:40 - INFO: System Diagnostic Information:
2025-10-30 09:22:40 - INFO: Python Version: 3.13.3
2025-10-30 09:22:40 - INFO: Operating System: Linux-6.6.87.2-microsoft-standard-WSL2-x86_64-with-glibc2.41
2025-10-30 09:22:40 - INFO: Hostname: StuMini
2025-10-30 09:22:40 - DEBUG: Starting new HTTPS connection (1): www.google.com:443
2025-10-30 09:22:40 - DEBUG: https://www.google.com:443 "GET / HTTP/1.1" 200 None
2025-10-30 09:22:40 - INFO: Internet Connectivity: OK (Status Code: 200)
2025-10-30 09:22:40 - INFO: Starting connection monitoring...
2025-10-30 09:22:40 - INFO: Monitoring parameters:
2025-10-30 09:22:40 - INFO: Monitoring parameters:
2025-10-30 09:22:40 - INFO: - API URL: http://sp.service.dc1.consul:8080/api/v2/transfer/info
2025-10-30 09:22:40 - INFO: - Tracker: https://t.myanonamouse.net/tracker.php/VPRYYAL-WpTwnr9G9aIN6044YVZ7x8Ao/announce
2025-10-30 09:22:40 - INFO: - Check Interval: 30 seconds
2025-10-30 09:22:40 - INFO: - Max Consecutive Failures: 1
2025-10-30 09:22:40 - ERROR: API request failed: HTTPConnectionPool(host='sp.service.dc1.consul', port=8080): Max retries exceeded with url: /api/v2/transfer/info (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7d73690dcad0>: Failed to establish a new connection: [Errno 111] Connection refused'))
2025-10-30 09:22:40 - WARNING: Connection unstable. Failures: 1
2025-10-30 09:22:40 - ERROR: Persistent connection failure. Initiating remediation.
2025-10-30 09:22:40 - WARNING: Connection instability detected. Starting remediation...
2025-10-30 09:22:40 - ERROR: qBittorrent login failed: HTTPConnectionPool(host='sp.service.dc1.consul', port=8080): Max retries exceeded with url: /api/v2/auth/login (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7d73690d8410>: Failed to establish a new connection: [Errno 111] Connection refused'))
2025-10-30 09:22:40 - ERROR: Could not log in to qBittorrent. Aborting remediation.
2025-10-30 09:22:57 - INFO: Connection monitoring stopped by user.
2025-10-30 09:23:01 - INFO: System Diagnostic Information:
2025-10-30 09:23:01 - INFO: Python Version: 3.13.3
2025-10-30 09:23:01 - INFO: Operating System: Linux-6.6.87.2-microsoft-standard-WSL2-x86_64-with-glibc2.41
2025-10-30 09:23:01 - INFO: Hostname: StuMini
2025-10-30 09:23:01 - DEBUG: Starting new HTTPS connection (1): www.google.com:443
2025-10-30 09:23:01 - DEBUG: https://www.google.com:443 "GET / HTTP/1.1" 200 None
2025-10-30 09:23:01 - INFO: Internet Connectivity: OK (Status Code: 200)
2025-10-30 09:23:01 - INFO: Starting connection monitoring...
2025-10-30 09:23:01 - INFO: Monitoring parameters:
2025-10-30 09:23:01 - INFO: Monitoring parameters:
2025-10-30 09:23:01 - INFO: - API URL: http://sp.service.dc1.consul:8080/api/v2/transfer/info
2025-10-30 09:23:01 - INFO: - Tracker: https://t.myanonamouse.net/tracker.php/VPRYYAL-WpTwnr9G9aIN6044YVZ7x8Ao/announce
2025-10-30 09:23:01 - INFO: - Check Interval: 30 seconds
2025-10-30 09:23:01 - INFO: - Max Consecutive Failures: 1
2025-10-30 09:23:01 - ERROR: API request failed: HTTPConnectionPool(host='sp.service.dc1.consul', port=8080): Max retries exceeded with url: /api/v2/transfer/info (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7239885f0ad0>: Failed to establish a new connection: [Errno 111] Connection refused'))
2025-10-30 09:23:01 - WARNING: Connection unstable. Failures: 1
2025-10-30 09:23:01 - ERROR: Persistent connection failure. Initiating remediation.
2025-10-30 09:23:01 - WARNING: Connection instability detected. Starting remediation...
2025-10-30 09:23:01 - ERROR: qBittorrent login failed: HTTPConnectionPool(host='sp.service.dc1.consul', port=8080): Max retries exceeded with url: /api/v2/auth/login (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7239885ec190>: Failed to establish a new connection: [Errno 111] Connection refused'))
2025-10-30 09:23:01 - ERROR: Could not log in to qBittorrent. Aborting remediation.
2025-10-30 09:23:03 - INFO: Connection monitoring stopped by user.
2025-10-30 09:23:04 - INFO: System Diagnostic Information:
2025-10-30 09:23:04 - INFO: Python Version: 3.13.3
2025-10-30 09:23:04 - INFO: Operating System: Linux-6.6.87.2-microsoft-standard-WSL2-x86_64-with-glibc2.41
2025-10-30 09:23:04 - INFO: Hostname: StuMini
2025-10-30 09:23:04 - DEBUG: Starting new HTTPS connection (1): www.google.com:443
2025-10-30 09:23:04 - DEBUG: https://www.google.com:443 "GET / HTTP/1.1" 200 None
2025-10-30 09:23:04 - INFO: Internet Connectivity: OK (Status Code: 200)
2025-10-30 09:23:04 - INFO: Starting connection monitoring...
2025-10-30 09:23:04 - INFO: Monitoring parameters:
2025-10-30 09:23:04 - INFO: Monitoring parameters:
2025-10-30 09:23:04 - INFO: - API URL: http://sp.service.dc1.consul:8080/api/v2/transfer/info
2025-10-30 09:23:04 - INFO: - Tracker: https://t.myanonamouse.net/tracker.php/VPRYYAL-WpTwnr9G9aIN6044YVZ7x8Ao/announce
2025-10-30 09:23:04 - INFO: - Check Interval: 30 seconds
2025-10-30 09:23:04 - INFO: - Max Consecutive Failures: 1
2025-10-30 09:23:04 - ERROR: API request failed: HTTPConnectionPool(host='sp.service.dc1.consul', port=8080): Max retries exceeded with url: /api/v2/transfer/info (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x70dadc964ad0>: Failed to establish a new connection: [Errno 111] Connection refused'))
2025-10-30 09:23:04 - WARNING: Connection unstable. Failures: 1
2025-10-30 09:23:04 - ERROR: Persistent connection failure. Initiating remediation.
2025-10-30 09:23:04 - WARNING: Connection instability detected. Starting remediation...
2025-10-30 09:23:04 - ERROR: qBittorrent login failed: HTTPConnectionPool(host='sp.service.dc1.consul', port=8080): Max retries exceeded with url: /api/v2/auth/login (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x70dadc960410>: Failed to establish a new connection: [Errno 111] Connection refused'))
2025-10-30 09:23:04 - ERROR: Could not log in to qBittorrent. Aborting remediation.
2025-10-30 09:23:37 - WARNING: Connection unstable. Failures: 2
2025-10-30 09:23:37 - ERROR: Persistent connection failure. Initiating remediation.
2025-10-30 09:23:37 - WARNING: Connection instability detected. Starting remediation...
2025-10-30 09:23:37 - INFO: Successfully logged into qBittorrent
2025-10-30 09:23:37 - ERROR: Failed to stop torrents: 404 Client Error: Not Found for url: http://sp.service.dc1.consul:8080/api/v2/torrents/pause
2025-10-30 09:23:37 - ERROR: Unexpected error in monitoring loop: ConnectionMonitor.restart_nomad_task_via_allocation() got multiple values for argument 'nomad_url'
2025-10-30 09:24:01 - INFO: System Diagnostic Information:
2025-10-30 09:24:01 - INFO: Python Version: 3.13.3
2025-10-30 09:24:01 - INFO: Operating System: Linux-6.6.87.2-microsoft-standard-WSL2-x86_64-with-glibc2.41
2025-10-30 09:24:01 - INFO: Hostname: StuMini
2025-10-30 09:24:01 - DEBUG: Starting new HTTPS connection (1): www.google.com:443
2025-10-30 09:24:02 - DEBUG: https://www.google.com:443 "GET / HTTP/1.1" 200 None
2025-10-30 09:24:02 - INFO: Internet Connectivity: OK (Status Code: 200)
2025-10-30 09:24:02 - INFO: Starting connection monitoring...
2025-10-30 09:24:02 - INFO: Monitoring parameters:
2025-10-30 09:24:02 - INFO: Monitoring parameters:
2025-10-30 09:24:02 - INFO: - API URL: http://sp.service.dc1.consul:8080/api/v2/transfer/info
2025-10-30 09:24:02 - INFO: - Tracker: https://t.myanonamouse.net/tracker.php/VPRYYAL-WpTwnr9G9aIN6044YVZ7x8Ao/announce
2025-10-30 09:24:02 - INFO: - Check Interval: 30 seconds
2025-10-30 09:24:02 - INFO: - Max Consecutive Failures: 1
2025-10-30 09:24:02 - DEBUG: Connected. DHT Nodes: 272
2025-10-30 09:24:34 - DEBUG: Connected. DHT Nodes: 272
2025-10-30 09:24:42 - INFO: Connection monitoring stopped by user.
2025-10-30 09:24:45 - INFO: System Diagnostic Information:
2025-10-30 09:24:45 - INFO: Python Version: 3.13.3
2025-10-30 09:24:45 - INFO: Operating System: Linux-6.6.87.2-microsoft-standard-WSL2-x86_64-with-glibc2.41
2025-10-30 09:24:45 - INFO: Hostname: StuMini
2025-10-30 09:24:45 - DEBUG: Starting new HTTPS connection (1): www.google.com:443
2025-10-30 09:24:45 - DEBUG: https://www.google.com:443 "GET / HTTP/1.1" 200 None
2025-10-30 09:24:45 - INFO: Internet Connectivity: OK (Status Code: 200)
2025-10-30 09:24:45 - INFO: Starting connection monitoring...
2025-10-30 09:24:45 - INFO: Monitoring parameters:
2025-10-30 09:24:45 - INFO: Monitoring parameters:
2025-10-30 09:24:45 - INFO: - API URL: http://sp.service.dc1.consul:8080/api/v2/transfer/info
2025-10-30 09:24:45 - INFO: - Tracker: https://t.myanonamouse.net/tracker.php/VPRYYAL-WpTwnr9G9aIN6044YVZ7x8Ao/announce
2025-10-30 09:24:45 - INFO: - Check Interval: 30 seconds
2025-10-30 09:24:45 - INFO: - Max Consecutive Failures: 20
2025-10-30 09:24:45 - WARNING: Connection unstable. Failures: 1
2025-10-30 09:24:59 - INFO: Connection monitoring stopped by user.
2025-10-30 09:25:00 - INFO: System Diagnostic Information:
2025-10-30 09:25:00 - INFO: Python Version: 3.13.3
2025-10-30 09:25:00 - INFO: Operating System: Linux-6.6.87.2-microsoft-standard-WSL2-x86_64-with-glibc2.41
2025-10-30 09:25:00 - INFO: Hostname: StuMini
2025-10-30 09:25:00 - DEBUG: Starting new HTTPS connection (1): www.google.com:443
2025-10-30 09:25:00 - DEBUG: https://www.google.com:443 "GET / HTTP/1.1" 200 None
2025-10-30 09:25:00 - INFO: Internet Connectivity: OK (Status Code: 200)
2025-10-30 09:25:00 - INFO: Starting connection monitoring...
2025-10-30 09:25:00 - INFO: Monitoring parameters:
2025-10-30 09:25:00 - INFO: Monitoring parameters:
2025-10-30 09:25:00 - INFO: - API URL: http://sp.service.dc1.consul:8080/api/v2/transfer/info
2025-10-30 09:25:00 - INFO: - Tracker: https://t.myanonamouse.net/tracker.php/VPRYYAL-WpTwnr9G9aIN6044YVZ7x8Ao/announce
2025-10-30 09:25:00 - INFO: - Check Interval: 30 seconds
2025-10-30 09:25:00 - INFO: - Max Consecutive Failures: 2
2025-10-30 09:25:00 - WARNING: Connection unstable. Failures: 1
2025-10-30 09:25:33 - WARNING: Connection unstable. Failures: 2
2025-10-30 09:25:33 - ERROR: Persistent connection failure. Initiating remediation.
2025-10-30 09:25:33 - WARNING: Connection instability detected. Starting remediation...
2025-10-30 09:25:33 - INFO: Successfully logged into qBittorrent
2025-10-30 09:25:33 - ERROR: Failed to stop torrents: 404 Client Error: Not Found for url: http://sp.service.dc1.consul:8080/api/v2/torrents/pause
2025-10-30 09:25:33 - ERROR: Unexpected error in monitoring loop: ConnectionMonitor.restart_nomad_task_via_allocation() got multiple values for argument 'nomad_url'
2025-10-30 09:29:29 - INFO: System Diagnostic Information:
2025-10-30 09:29:29 - INFO: Python Version: 3.13.3
2025-10-30 09:29:29 - INFO: Operating System: Linux-6.6.87.2-microsoft-standard-WSL2-x86_64-with-glibc2.41
2025-10-30 09:29:29 - INFO: Hostname: StuMini
2025-10-30 09:29:29 - DEBUG: Starting new HTTPS connection (1): www.google.com:443
2025-10-30 09:29:29 - DEBUG: https://www.google.com:443 "GET / HTTP/1.1" 200 None
2025-10-30 09:29:29 - INFO: Internet Connectivity: OK (Status Code: 200)
2025-10-30 09:29:29 - INFO: Starting connection monitoring...
2025-10-30 09:29:29 - INFO: Monitoring parameters:
2025-10-30 09:29:29 - INFO: Monitoring parameters:
2025-10-30 09:29:29 - INFO: - API URL: http://sp.service.dc1.consul:8080/api/v2/transfer/info
2025-10-30 09:29:29 - INFO: - Tracker: https://t.myanonamouse.net/tracker.php/VPRYYAL-WpTwnr9G9aIN6044YVZ7x8Ao/announce
2025-10-30 09:29:29 - INFO: - Check Interval: 30 seconds
2025-10-30 09:29:29 - INFO: - Max Consecutive Failures: 2
2025-10-30 09:29:29 - WARNING: Connection unstable. Failures: 1
2025-10-30 09:30:02 - WARNING: Connection unstable. Failures: 2
2025-10-30 09:30:02 - ERROR: Persistent connection failure. Initiating remediation.
2025-10-30 09:30:02 - WARNING: Connection instability detected. Starting remediation...
2025-10-30 09:30:02 - INFO: Successfully logged into qBittorrent
2025-10-30 09:30:03 - INFO: Stopped 145 torrents for tracker https://t.myanonamouse.net/tracker.php/VPRYYAL-WpTwnr9G9aIN6044YVZ7x8Ao/announce
2025-10-30 09:30:03 - ERROR: Unexpected error in monitoring loop: ConnectionMonitor.restart_nomad_task_via_allocation() got multiple values for argument 'nomad_url'
2025-10-30 09:32:34 - INFO: System Diagnostic Information:
2025-10-30 09:32:34 - INFO: Python Version: 3.13.3
2025-10-30 09:32:34 - INFO: Operating System: Linux-6.6.87.2-microsoft-standard-WSL2-x86_64-with-glibc2.41
2025-10-30 09:32:34 - INFO: Hostname: StuMini
2025-10-30 09:32:34 - DEBUG: Starting new HTTPS connection (1): www.google.com:443
2025-10-30 09:32:34 - DEBUG: https://www.google.com:443 "GET / HTTP/1.1" 200 None
2025-10-30 09:32:34 - INFO: Internet Connectivity: OK (Status Code: 200)
2025-10-30 09:32:34 - INFO: Starting connection monitoring...
2025-10-30 09:32:34 - INFO: Monitoring parameters:
2025-10-30 09:32:34 - INFO: Monitoring parameters:
2025-10-30 09:32:34 - INFO: - API URL: http://sp.service.dc1.consul:8080/api/v2/transfer/info
2025-10-30 09:32:34 - INFO: - Tracker: https://t.myanonamouse.net/tracker.php/VPRYYAL-WpTwnr9G9aIN6044YVZ7x8Ao/announce
2025-10-30 09:32:34 - INFO: - Check Interval: 30 seconds
2025-10-30 09:32:34 - INFO: - Max Consecutive Failures: 2
2025-10-30 09:32:34 - WARNING: Connection unstable. Failures: 1
2025-10-30 09:33:06 - WARNING: Connection unstable. Failures: 2
2025-10-30 09:33:06 - ERROR: Persistent connection failure. Initiating remediation.
2025-10-30 09:33:06 - WARNING: Connection instability detected. Starting remediation...
2025-10-30 09:33:06 - INFO: Successfully logged into qBittorrent
2025-10-30 09:33:06 - INFO: Stopped 145 torrents for tracker https://t.myanonamouse.net/tracker.php/VPRYYAL-WpTwnr9G9aIN6044YVZ7x8Ao/announce
2025-10-30 09:33:06 - ERROR: Unexpected error in monitoring loop: ConnectionMonitor.restart_nomad_task_via_allocation() got multiple values for argument 'nomad_url'
2025-10-30 09:33:39 - WARNING: Connection unstable. Failures: 3
2025-10-30 09:33:39 - ERROR: Persistent connection failure. Initiating remediation.
2025-10-30 09:33:39 - WARNING: Connection instability detected. Starting remediation...
2025-10-30 09:33:39 - INFO: Successfully logged into qBittorrent
2025-10-30 09:33:39 - INFO: Stopped 145 torrents for tracker https://t.myanonamouse.net/tracker.php/VPRYYAL-WpTwnr9G9aIN6044YVZ7x8Ao/announce
2025-10-30 09:33:39 - ERROR: Unexpected error in monitoring loop: ConnectionMonitor.restart_nomad_task_via_allocation() got multiple values for argument 'nomad_url'
2025-10-30 09:41:31 - INFO: System Diagnostic Information:
2025-10-30 09:41:31 - INFO: Python Version: 3.13.3
2025-10-30 09:41:31 - INFO: Operating System: Linux-6.6.87.2-microsoft-standard-WSL2-x86_64-with-glibc2.41
2025-10-30 09:41:31 - INFO: Hostname: StuMini
2025-10-30 09:41:31 - DEBUG: Starting new HTTPS connection (1): www.google.com:443
2025-10-30 09:41:31 - DEBUG: https://www.google.com:443 "GET / HTTP/1.1" 200 None
2025-10-30 09:41:31 - INFO: Internet Connectivity: OK (Status Code: 200)
2025-10-30 09:41:31 - INFO: Starting connection monitoring...
2025-10-30 09:41:31 - INFO: Monitoring parameters:
2025-10-30 09:41:31 - INFO: Monitoring parameters:
2025-10-30 09:41:31 - INFO: - API URL: http://sp.service.dc1.consul:8080/api/v2/transfer/info
2025-10-30 09:41:31 - INFO: - Tracker: https://t.myanonamouse.net/tracker.php/VPRYYAL-WpTwnr9G9aIN6044YVZ7x8Ao/announce
2025-10-30 09:41:31 - INFO: - Check Interval: 30 seconds
2025-10-30 09:41:31 - INFO: - Max Consecutive Failures: 2
2025-10-30 09:41:31 - WARNING: Connection unstable. Failures: 1
2025-10-30 09:42:04 - WARNING: Connection unstable. Failures: 2
2025-10-30 09:42:04 - ERROR: Persistent connection failure. Initiating remediation.
2025-10-30 09:42:04 - WARNING: Connection instability detected. Starting remediation...
2025-10-30 09:42:04 - INFO: Successfully logged into qBittorrent
2025-10-30 09:42:04 - INFO: Stopped 145 torrents for tracker https://t.myanonamouse.net/tracker.php/VPRYYAL-WpTwnr9G9aIN6044YVZ7x8Ao/announce
2025-10-30 09:42:04 - ERROR: Unexpected error in monitoring loop: ConnectionMonitor.restart_nomad_task_via_allocation() got multiple values for argument 'nomad_url'
2025-10-30 09:44:00 - INFO: System Diagnostic Information:
2025-10-30 09:44:00 - INFO: Python Version: 3.13.3
2025-10-30 09:44:00 - INFO: Operating System: Linux-6.6.87.2-microsoft-standard-WSL2-x86_64-with-glibc2.41
2025-10-30 09:44:00 - INFO: Hostname: StuMini
2025-10-30 09:44:00 - DEBUG: Starting new HTTPS connection (1): www.google.com:443
2025-10-30 09:44:00 - DEBUG: https://www.google.com:443 "GET / HTTP/1.1" 200 None
2025-10-30 09:44:00 - INFO: Internet Connectivity: OK (Status Code: 200)
2025-10-30 09:44:00 - INFO: Starting connection monitoring...
2025-10-30 09:44:00 - INFO: Monitoring parameters:
2025-10-30 09:44:00 - INFO: Monitoring parameters:
2025-10-30 09:44:00 - INFO: - API URL: http://sp.service.dc1.consul:8080/api/v2/transfer/info
2025-10-30 09:44:00 - INFO: - Tracker: https://t.myanonamouse.net/tracker.php/VPRYYAL-WpTwnr9G9aIN6044YVZ7x8Ao/announce
2025-10-30 09:44:00 - INFO: - Check Interval: 30 seconds
2025-10-30 09:44:00 - INFO: - Max Consecutive Failures: 2
2025-10-30 09:44:00 - WARNING: Connection unstable. Failures: 1
2025-10-30 09:44:33 - WARNING: Connection unstable. Failures: 2
2025-10-30 09:44:33 - ERROR: Persistent connection failure. Initiating remediation.
2025-10-30 09:44:33 - WARNING: Connection instability detected. Starting remediation...
2025-10-30 09:44:33 - INFO: Successfully logged into qBittorrent
2025-10-30 09:44:33 - INFO: Stopped 145 torrents for tracker https://t.myanonamouse.net/tracker.php/VPRYYAL-WpTwnr9G9aIN6044YVZ7x8Ao/announce
2025-10-30 09:44:33 - ERROR: Unexpected error in monitoring loop: ConnectionMonitor.restart_nomad_task_via_allocation() got an unexpected keyword argument 'nomad_url'
2025-10-30 09:46:56 - INFO: System Diagnostic Information:
2025-10-30 09:46:56 - INFO: Python Version: 3.13.3
2025-10-30 09:46:56 - INFO: Operating System: Linux-6.6.87.2-microsoft-standard-WSL2-x86_64-with-glibc2.41
2025-10-30 09:46:56 - INFO: Hostname: StuMini
2025-10-30 09:46:56 - DEBUG: Starting new HTTPS connection (1): www.google.com:443
2025-10-30 09:46:56 - DEBUG: https://www.google.com:443 "GET / HTTP/1.1" 200 None
2025-10-30 09:46:56 - INFO: Internet Connectivity: OK (Status Code: 200)
2025-10-30 09:46:56 - INFO: Starting connection monitoring...
2025-10-30 09:46:56 - INFO: Monitoring parameters:
2025-10-30 09:46:56 - INFO: Monitoring parameters:
2025-10-30 09:46:56 - INFO: - API URL: http://sp.service.dc1.consul:8080/api/v2/transfer/info
2025-10-30 09:46:56 - INFO: - Tracker: https://t.myanonamouse.net/tracker.php/VPRYYAL-WpTwnr9G9aIN6044YVZ7x8Ao/announce
2025-10-30 09:46:56 - INFO: - Check Interval: 30 seconds
2025-10-30 09:46:56 - INFO: - Max Consecutive Failures: 2
2025-10-30 09:46:56 - WARNING: Connection unstable. Failures: 1
2025-10-30 09:47:30 - WARNING: Connection unstable. Failures: 2
2025-10-30 09:47:30 - ERROR: Persistent connection failure. Initiating remediation.
2025-10-30 09:47:30 - WARNING: Connection instability detected. Starting remediation...
2025-10-30 09:47:30 - INFO: Successfully logged into qBittorrent
2025-10-30 09:47:30 - INFO: Stopped 145 torrents for tracker https://t.myanonamouse.net/tracker.php/VPRYYAL-WpTwnr9G9aIN6044YVZ7x8Ao/announce
2025-10-30 09:47:30 - INFO: Fetching allocations for job 'qbittorrent'...
2025-10-30 09:47:30 - INFO: Restarting task 'qbittorrent' in job 'qbittorrent'...
2025-10-30 09:47:35 - INFO: Successfully restarted task 'qbittorrent' in job 'qbittorrent'
2025-10-30 09:48:40 - INFO: Waiting 30.0 minutes for connection stabilization...

245
nomad_restart.py Executable file
View File

@@ -0,0 +1,245 @@
#!/usr/bin/env python3
"""
Standalone script to test Nomad task restart functionality.
"""
import requests
import time
import logging
import sys
import argparse
from typing import Optional
# Configure logging
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger(__name__)
def restart_nomad_task_via_allocation(
nomad_url: str,
job_id: str,
task_name: str,
namespace: str = "default",
token: Optional[str] = None,
wait_time: int = 60
) -> bool:
"""
Restart a specific task in a Nomad job by stopping its allocation.
This is the recommended approach using the Nomad API.
Args:
nomad_url: Base URL of the Nomad server (e.g., 'http://localhost:4646')
job_id: The ID of the job containing the task
task_name: The name of the task to restart
namespace: The namespace of the job (default: 'default')
token: Optional ACL token for authentication
wait_time: Seconds to wait after restart (default: 60)
Returns:
bool: True if restart succeeded, False otherwise
"""
headers = {}
if token:
headers['X-Nomad-Token'] = token
try:
# Get allocations for the job
allocs_url = f"{nomad_url}/v1/job/{job_id}/allocations"
params = {'namespace': namespace}
logger.info(f"Fetching allocations for job '{job_id}' from: {allocs_url}")
response = requests.get(allocs_url, headers=headers, params=params, timeout=10)
response.raise_for_status()
allocations = response.json()
logger.info(f"Found {len(allocations)} total allocations")
# Find allocation containing the task
target_alloc = None
for alloc in allocations:
alloc_id = alloc['ID']
client_status = alloc['ClientStatus']
logger.debug(f"Allocation {alloc_id}: Status={client_status}")
if client_status == 'running':
task_states = alloc.get('TaskStates', {})
logger.debug(f" Tasks in this allocation: {list(task_states.keys())}")
if task_name in task_states:
target_alloc = alloc
logger.info(f"Found target task '{task_name}' in allocation {alloc_id}")
break
if not target_alloc:
logger.error(f"No running allocation found for task '{task_name}' in job '{job_id}'")
logger.error(f"Available tasks in running allocations:")
for alloc in allocations:
if alloc['ClientStatus'] == 'running':
task_states = alloc.get('TaskStates', {})
logger.error(f" Allocation {alloc['ID']}: {list(task_states.keys())}")
return False
# Restart just the specific task within the allocation
alloc_id = target_alloc['ID']
restart_url = f"{nomad_url}/v1/client/allocation/{alloc_id}/restart"
# Payload to restart only the specific task
payload = {
"TaskName": task_name
}
logger.info(f"Restarting task '{task_name}' in allocation {alloc_id}...")
response = requests.post(restart_url, headers=headers, params=params, json=payload, timeout=10)
logger.debug(f"Response Status: {response.status_code}")
logger.debug(f"Response Content: {response.text}")
if response.status_code in [200, 204]:
logger.info(f"✓ Successfully triggered restart for task '{task_name}' in job '{job_id}'")
logger.info(f"Waiting {wait_time} seconds for job to stabilize...")
time.sleep(wait_time)
logger.info("Wait complete")
return True
else:
logger.error(f"✗ Failed to stop allocation: {response.status_code} - {response.text}")
return False
except requests.RequestException as e:
logger.error(f"✗ Request failed: {e}")
return False
except Exception as e:
logger.error(f"✗ Unexpected error: {e}")
return False
def list_job_tasks(nomad_url: str, job_id: str, namespace: str = "default", token: Optional[str] = None):
"""
List all tasks in a job to help identify the correct task name.
"""
headers = {}
if token:
headers['X-Nomad-Token'] = token
try:
allocs_url = f"{nomad_url}/v1/job/{job_id}/allocations"
params = {'namespace': namespace}
logger.info(f"Fetching allocations for job '{job_id}'...")
response = requests.get(allocs_url, headers=headers, params=params, timeout=10)
response.raise_for_status()
allocations = response.json()
print(f"\n{'='*60}")
print(f"Job: {job_id}")
print(f"Total Allocations: {len(allocations)}")
print(f"{'='*60}\n")
tasks_found = set()
for alloc in allocations:
alloc_id = alloc['ID']
client_status = alloc['ClientStatus']
task_states = alloc.get('TaskStates', {})
print(f"Allocation: {alloc_id}")
print(f" Status: {client_status}")
print(f" Tasks:")
for task_name, task_state in task_states.items():
state = task_state.get('State', 'unknown')
print(f" - {task_name} ({state})")
tasks_found.add(task_name)
print()
print(f"{'='*60}")
print(f"Unique task names found: {', '.join(sorted(tasks_found))}")
print(f"{'='*60}\n")
return list(tasks_found)
except requests.RequestException as e:
logger.error(f"Failed to list tasks: {e}")
return []
def main():
parser = argparse.ArgumentParser(
description='Test Nomad task restart functionality',
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
# List all tasks in a job
python script.py --list-tasks --job tasktorestart
# Restart a specific task
python script.py --job tasktorestart --task my-task-name
# With custom Nomad URL
python script.py --url http://nomad.example.com:4646 --job tasktorestart --task my-task
# With ACL token
python script.py --job tasktorestart --task my-task --token your-token-here
"""
)
parser.add_argument('--url', default='http://192.168.4.36:4646',
help='Nomad server URL (default: http://localhost:4646)')
parser.add_argument('--job', default='tasktorestart',
help='Job ID (default: tasktorestart)')
parser.add_argument('--task',
help='Task name to restart')
parser.add_argument('--namespace', default='default',
help='Namespace (default: default)')
parser.add_argument('--token',
help='ACL token for authentication')
parser.add_argument('--wait', type=int, default=60,
help='Seconds to wait after restart (default: 60)')
parser.add_argument('--list-tasks', action='store_true',
help='List all tasks in the job instead of restarting')
args = parser.parse_args()
# List tasks mode
if args.list_tasks:
logger.info("Listing tasks in job...")
list_job_tasks(args.url, args.job, args.namespace, args.token)
return 0
# Restart mode
if not args.task:
logger.error("Error: --task is required for restart (or use --list-tasks to see available tasks)")
parser.print_help()
return 1
logger.info(f"Starting Nomad task restart test...")
logger.info(f" Nomad URL: {args.url}")
logger.info(f" Job ID: {args.job}")
logger.info(f" Task Name: {args.task}")
logger.info(f" Namespace: {args.namespace}")
logger.info(f" Wait Time: {args.wait}s")
print()
success = restart_nomad_task_via_allocation(
nomad_url=args.url,
job_id=args.job,
task_name=args.task,
namespace=args.namespace,
token=args.token,
wait_time=args.wait
)
if success:
logger.info("\n" + "="*60)
logger.info("✓ TEST PASSED: Task restart succeeded")
logger.info("="*60)
return 0
else:
logger.error("\n" + "="*60)
logger.error("✗ TEST FAILED: Task restart failed")
logger.error("="*60)
return 1
if __name__ == "__main__":
sys.exit(main())