Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

Keep CLI commands from starting the daemons

Juan Denis051ea4d31d63
diff --git a/backend/cli.py b/backend/cli.py
index 3ce406e8..99530a00 100644
--- a/backend/cli.py
+++ b/backend/cli.py
@@ -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
diff --git a/backend/tests/test_cli_skips_background.py b/backend/tests/test_cli_skips_background.py
new file mode 100644
index 00000000..cd210b28
--- /dev/null
+++ b/backend/tests/test_cli_skips_background.py
@@ -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'