-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcheck_systemd_env.py
More file actions
79 lines (71 loc) · 2.85 KB
/
check_systemd_env.py
File metadata and controls
79 lines (71 loc) · 2.85 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
#!/usr/bin/env python3
"""
Script to help debug systemd .env file loading issues
"""
import os
import subprocess
import pwd
print("=== Systemd Environment Debug ===")
# Get current user info
current_user = pwd.getpwuid(os.getuid()).pw_name
home_dir = os.path.expanduser("~")
print(f"Current user: {current_user}")
print(f"Home directory: {home_dir}")
print(f"Current working directory: {os.getcwd()}")
# Check possible .env file locations
possible_env_paths = [
".env", # relative to current directory
"./thywill/.env", # if running from parent directory
f"{home_dir}/.env", # in home directory
f"{home_dir}/thywill/.env", # in thywill subdirectory
"/home/thywill/thywill/.env", # absolute path from systemd service
]
print("\n=== Checking .env file locations ===")
for path in possible_env_paths:
exists = os.path.exists(path)
abs_path = os.path.abspath(path) if exists else "N/A"
print(f"{path}: {'EXISTS' if exists else 'NOT FOUND'}")
if exists:
print(f" Absolute path: {abs_path}")
try:
with open(path, 'r') as f:
lines = f.readlines()
token_lines = [l.strip() for l in lines if 'INVITE_TOKEN_EXPIRATION_HOURS' in l]
if token_lines:
print(f" INVITE_TOKEN_EXPIRATION_HOURS line: {token_lines[0]}")
else:
print(" No INVITE_TOKEN_EXPIRATION_HOURS found in file")
except Exception as e:
print(f" Error reading file: {e}")
print()
print("=== Systemd Service Information ===")
try:
# Check if thywill service exists and get its status
result = subprocess.run(['systemctl', 'status', 'thywill'],
capture_output=True, text=True, timeout=10)
print("Systemd service status:")
print(result.stdout)
if result.stderr:
print("Stderr:", result.stderr)
except Exception as e:
print(f"Could not get systemd status: {e}")
try:
# Try to get the service file content
result = subprocess.run(['systemctl', 'cat', 'thywill'],
capture_output=True, text=True, timeout=10)
print("\nSystemd service file content:")
print(result.stdout)
if result.stderr:
print("Stderr:", result.stderr)
except Exception as e:
print(f"Could not get systemd service file: {e}")
print("\n=== Current Environment Variables ===")
invite_hours = os.getenv("INVITE_TOKEN_EXPIRATION_HOURS")
print(f"INVITE_TOKEN_EXPIRATION_HOURS: {invite_hours}")
print(f"PORT: {os.getenv('PORT', 'not set')}")
print(f"ANTHROPIC_API_KEY: {'SET' if os.getenv('ANTHROPIC_API_KEY') else 'NOT SET'}")
# Show all environment variables with TOKEN, HOUR, or starting with INVITE
print("\nRelevant environment variables:")
for key, value in sorted(os.environ.items()):
if any(word in key.upper() for word in ['TOKEN', 'HOUR', 'INVITE', 'PORT']):
print(f" {key}={value}")