Keep CLI commands from starting the daemons

cli.py runs as a plain python script, so the factory's flask-argv sniff
never matched it: every serverkit verb booted a second job consumer,
scheduler and relay beside the live panel, whose boot reconcile marks
the panel's in-flight deploys failed.
This commit is contained in:
Juan Denis committed 2026-10-10 13:03:37 -04:00
1 parent 4e45ecb5f5
commit 051ea4d31d
2 files changed
+38

No files matched your search

+5
View File
@@ -41,6 +41,11 @@ def load_env():
# Load env before any other imports that might use config
_env_loaded = load_env()
# A CLI command is a one-shot beside the running panel: it must not start a
# second job consumer, scheduler and relay (the boot reconcile would mark the
# panel's in-flight deploys failed). Queued work is run by the panel itself.
os.environ.setdefault('SERVERKIT_SKIP_BACKGROUND', '1')
from werkzeug.security import generate_password_hash
from app import create_app, db
from app.models import User
@@ -0,0 +1,33 @@
"""`serverkit <verb>` must not boot a second set of background daemons.
The CLI runs as `python cli.py ...`, so the app factory's `flask`-argv sniff
never matched it: every command started a job consumer, scheduler and relay
beside the live panel. Importing cli.py now opts the process out.
"""
import os
import subprocess
import sys
BACKEND = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
PROBE = ("import os, cli; "
"print(os.environ.get('SERVERKIT_SKIP_BACKGROUND'))")
def _probe(**env):
child_env = {k: v for k, v in os.environ.items()
if k != 'SERVERKIT_SKIP_BACKGROUND'}
child_env.update(env)
out = subprocess.run([sys.executable, '-c', PROBE], cwd=BACKEND,
env=child_env, capture_output=True, text=True,
timeout=120)
assert out.returncode == 0, out.stderr
return out.stdout.strip().splitlines()[-1]
def test_cli_import_skips_background_daemons():
assert _probe() == '1'
def test_explicit_operator_setting_wins():
assert _probe(SERVERKIT_SKIP_BACKGROUND='0') == '0'