()
| 153 | } |
| 154 | |
| 155 | async function status(): Promise<ServiceStatus> { |
| 156 | const unitPath = deps.unitPath(); |
| 157 | const plan = readInstallPlan(); |
| 158 | const installed = existsSync(unitPath); |
| 159 | |
| 160 | const base: ServiceStatus = { |
| 161 | platform: 'linux', |
| 162 | installed, |
| 163 | running: false, |
| 164 | unitName: KIMI_SERVER_SYSTEMD_UNIT, |
| 165 | ...(plan?.host !== undefined ? { host: plan.host } : {}), |
| 166 | ...(plan?.port !== undefined ? { port: plan.port } : {}), |
| 167 | logPath: deps.logPath(), |
| 168 | }; |
| 169 | |
| 170 | if (!installed) { |
| 171 | return { ...base, notes: ['systemd unit is not installed.'] }; |
| 172 | } |
| 173 | |
| 174 | const show = await deps.execSystemctl([ |
| 175 | 'show', |
| 176 | KIMI_SERVER_SYSTEMD_UNIT, |
| 177 | '--property=ActiveState,SubState,MainPID,ExecStart', |
| 178 | ]); |
| 179 | if (show.code !== 0) { |
| 180 | return { |
| 181 | ...base, |
| 182 | notes: [ |
| 183 | `systemctl --user show failed (code ${show.code}): ${detail(show) ?? 'unknown'}.`, |
| 184 | 'The unit is on disk but systemd could not report its state.', |
| 185 | ], |
| 186 | }; |
| 187 | } |
| 188 | const fields = parseSystemctlShow(show.stdout); |
| 189 | const activeState = fields['ActiveState']; |
| 190 | const subState = fields['SubState']; |
| 191 | const mainPid = Number.parseInt(fields['MainPID'] ?? '', 10); |
| 192 | const running = activeState === 'active' && subState !== 'failed'; |
| 193 | return { |
| 194 | ...base, |
| 195 | running, |
| 196 | ...(Number.isFinite(mainPid) && mainPid > 0 ? { pid: mainPid } : {}), |
| 197 | notes: [`systemd state: ${activeState ?? 'unknown'}/${subState ?? 'unknown'}`], |
| 198 | }; |
| 199 | } |
| 200 | |
| 201 | return { install, uninstall, start, stop, restart, status }; |
| 202 | } |
nothing calls this directly
no test coverage detected