fix: proper error handling for access denied, kill deploy nginx before systemd
This commit is contained in:
parent
03f56964b9
commit
076b801eda
1 changed files with 12 additions and 6 deletions
|
|
@ -139,13 +139,18 @@ http {{
|
||||||
print(f"[{name}] Registering node...")
|
print(f"[{name}] Registering node...")
|
||||||
r = run(f"bash -c 'source {DEPLOY_TO}/env.list 2>/dev/null; {DEPLOY_TO}/register-node job:register -token {token} -host {api_host}'",
|
r = run(f"bash -c 'source {DEPLOY_TO}/env.list 2>/dev/null; {DEPLOY_TO}/register-node job:register -token {token} -host {api_host}'",
|
||||||
timeout=120)
|
timeout=120)
|
||||||
if r.returncode != 0 and "node instance registered" not in r.stdout:
|
# Check for success indicators
|
||||||
print(f"Registration output:\n{r.stdout}\n{r.stderr}")
|
registered = "node instance registered" in r.stdout or "init done" in r.stdout
|
||||||
# Not fatal — check if UUID assigned
|
access_denied = "access denied" in r.stdout + r.stderr
|
||||||
if not os.path.exists(f"{DEPLOY_TO}/etc/wallarm/node.yaml"):
|
invalid_token = "invalid token" in (r.stdout + r.stderr).lower()
|
||||||
raise RuntimeError(f"Registration failed: {r.stderr or r.stdout}")
|
|
||||||
|
|
||||||
# Move to instance
|
if access_denied or invalid_token:
|
||||||
|
raise RuntimeError("Token rejected by Wallarm. Check token permissions and cloud region.")
|
||||||
|
if not registered:
|
||||||
|
raise RuntimeError(f"Registration failed:\n{r.stdout[-500:]}\n{r.stderr[-500:]}")
|
||||||
|
|
||||||
|
# Kill deploy nginx + move to instance
|
||||||
|
run(f"pkill -9 -f '{DEPLOY_TO}/nginx' 2>/dev/null; true", timeout=5)
|
||||||
print(f"[{name}] Installing...")
|
print(f"[{name}] Installing...")
|
||||||
shutil.rmtree(instance, ignore_errors=True)
|
shutil.rmtree(instance, ignore_errors=True)
|
||||||
os.makedirs(os.path.dirname(instance), exist_ok=True)
|
os.makedirs(os.path.dirname(instance), exist_ok=True)
|
||||||
|
|
@ -383,6 +388,7 @@ def main():
|
||||||
elif c.lower() == "q": break
|
elif c.lower() == "q": break
|
||||||
|
|
||||||
def deploy_all():
|
def deploy_all():
|
||||||
|
print("Deploying all from fw.conf...")
|
||||||
cfg = load_config()
|
cfg = load_config()
|
||||||
for name, nc in cfg.get("nodes", {}).items():
|
for name, nc in cfg.get("nodes", {}).items():
|
||||||
if is_deployed(name):
|
if is_deployed(name):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue