# plugin_services — local service status board for SCORPIOX BOT `services` is a zero-dependency C99 plugin that shows every service your node's init system manages — state, enabled flag, PID, memory and uptime — in a responsive dark/light board inside SCORPIOX BOT, and optionally starts, stops or restarts one. ``` $ ./plugin_services --meta {"name":"services","desc":"System services"} ``` ## What it reads | Platform | Source | Detail | |---|---|---| | **Linux** | `systemctl list-units --type=service --all --output=json` | falls back to the plain table on systemd < 248, then to `list-unit-files`; one `systemctl show … -p Id -p MainPID -p ActiveEnterTimestamp -p MemoryCurrent -p UnitFileState …` pass fills PID / memory / since / enabled | | **Linux (no init)** | `/proc//{comm,stat,statm}` + `/proc/uptime` | in a container with no systemd it reports `"init_system":"none"` and lists the daemons that have been up ≥ 5 minutes, with their RSS and uptime | | **macOS** | `launchctl list` | pid / status / label, with RSS and start time from one `ps -o pid=,rss=,lstart=` pass | | **Windows** | `OpenSCManagerA` + `EnumServicesStatusExA` + `QueryServiceConfigA` | no shell, no `popen`, no service name on a command line | Nothing is written. Nothing is fetched. The binary opens no socket of any kind. ## API All actions are behind node auth — `X-Bot-Password`, `Authorization: Bearer …`, or `?pwd=` — and auth is a no-op only when `BOT_PASSWORD` is unset on the node. | Action | Method | Response | |---|---|---| | `?action=list[&filter=failed\|running\|inactive\|all]` | GET | `{"ok":true,"init_system":"systemd","control_enabled":false,"count":4,"summary":{"running":2,"failed":1,"inactive":1},"services":[…]} ` | | `?action=show&unit=nginx.service` | GET | `{"ok":true,…,"service":{…}}` or 404 | | `?action=control&unit=nginx.service&op=start\|stop\|restart` | POST | `{"ok":true,"unit":"…","op":"…","control_enabled":true}` | Each service object is: ```json {"name":"nginx.service","description":"A high performance web server", "active":"active","sub":"running","enabled":"enabled", "pid":4242,"memory_bytes":10485760,"since":"Wed 2026-11-12 04:00:00 UTC", "failed":false} ``` `memory_bytes` is `null` when the platform does not report it (or when systemd returns its `18446744073709551615` sentinel). Rows are sorted failed → running → inactive, then by name. ## Control is off unless the operator turns it on The plugin is **read-only by default**. Start / stop / restart exist only when the node sets: ```sh SERVICES_ALLOW_CONTROL=1 ``` Without it every control request is `403 {"error":"control_disabled"}` and the page does not render the buttons at all (it reads `control_enabled` from the list response, so the UI can never show a button that would fail). When it is enabled: * the unit name must match `[A-Za-z0-9@._:\-]{1,160}` — `a;reboot`, `$(id)`, a newline, `../../etc/passwd` and `-oProxyCommand=x` are all a `400 invalid unit`, before anything is executed; * the name is passed to `execvp("systemctl", {"systemctl", op, unit, NULL})` as a **separate argv element**. No shell is ever involved, on any platform; * on Windows it is `OpenServiceA` + `StartServiceA` / `ControlService(STOP)`. No command line exists to escape from; * on macOS it is `launchctl kickstart -k