diff --git a/.vscode/tasks.json b/.vscode/tasks.json index c5a9c3b..7018542 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -8,6 +8,13 @@ "command": "{ [ -d .venv ] || { python3 -m venv .venv && .venv/bin/pip install -q -r app/requirements.txt; }; } && (cd app/web && { [ -d node_modules ] || npm install; } && npm run build) && .venv/bin/python app/server/server.py", "isBackground": true, "problemMatcher": [] + }, + { + "label": "Reload the service", + "detail": "After a change of the code: rebuilds the page and relaunches the systemd service aimsight-app on http://127.0.0.1:8770 (README.md, Run as a service)", + "type": "shell", + "command": "systemctl --user restart aimsight-app && systemctl --user is-active aimsight-app && echo http://127.0.0.1:8770 || { journalctl --user -u aimsight-app -n 30 --no-pager; exit 1; }", + "problemMatcher": [] } ] } diff --git a/README.md b/README.md index 348c739..99b1552 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,16 @@ cd app/web && npm install && npm run build && cd ../.. The page opens on `http://127.0.0.1:8770`. `claude` (Claude Code, logged in to the subscription) must be on the `PATH` for the Analysis tab. +### Run as a service + +Without VS Code, the app runs as a systemd user service of WSL (`app/aimsight-app.service`, with `systemd=true` in `/etc/wsl.conf`), started with WSL; the page stays on `http://127.0.0.1:8770`. Once: + +```bash +systemctl --user enable --now ~/aimsight-app/app/aimsight-app.service +``` + +After a change of the code, a restart rebuilds the page and relaunches the server: `systemctl --user restart aimsight-app`. The log: `journalctl --user -u aimsight-app -f`. Stop it before launching the VS Code task **Run app** (same port). + ## Pump the data The pumping is in the `~/aimsight-data` repository (`extraction/`, VS Code tasks **pump** and **pump a range**); user guide `~/aimsight-data/extraction/README.md`. diff --git a/app/aimsight-app.service b/app/aimsight-app.service new file mode 100644 index 0000000..170856f --- /dev/null +++ b/app/aimsight-app.service @@ -0,0 +1,15 @@ +# The app as a systemd user service (WSL), without VS Code: README.md, "Run as a service". +[Unit] +Description=AIMsight diagnostic app (http://127.0.0.1:8770) + +[Service] +WorkingDirectory=%h/aimsight-app +# claude (Claude Code, subscription) is in ~/.local/bin, which a service does not get from the shell +Environment=PATH=%h/.local/bin:/usr/local/bin:/usr/bin:/bin +# a restart rebuilds the page, so a change of the code needs only: systemctl --user restart aimsight-app +ExecStartPre=/bin/sh -c 'cd app/web && npm run build' +ExecStart=%h/aimsight-app/.venv/bin/python app/server/server.py --no-browser +Restart=on-failure + +[Install] +WantedBy=default.target