@@ -2,12 +2,14 @@ import { DATABASE_COMPACTION_RECOMMENDED_BYTES } from "@t3tools/contracts";
22import * as Console from "effect/Console" ;
33import * as Effect from "effect/Effect" ;
44import * as Layer from "effect/Layer" ;
5+ import * as Option from "effect/Option" ;
56import { Command , Flag , GlobalFlag , Prompt } from "effect/cli" ;
67
78import * as BootService from "../cloud/bootService.ts" ;
89import * as DatabaseMaintenance from "../persistence/DatabaseMaintenance.ts" ;
910import { projectLocationFlags , resolveCliAuthConfig } from "./config.ts" ;
1011import * as CliService from "./service.ts" ;
12+ import { isProcessAlive , readPersistedServerRuntimeState } from "../serverRuntimeState.ts" ;
1113
1214const formatBytes = ( bytes : number ) =>
1315 bytes >= 1024 ** 3
@@ -18,8 +20,37 @@ const formatBytes = (bytes: number) =>
1820
1921export const runDoctor = Effect . fn ( "runDoctor" ) ( function * (
2022 databasePath : string ,
21- options : { readonly fix : boolean ; readonly dryRun : boolean ; readonly interactive ?: boolean } ,
23+ options : {
24+ readonly fix : boolean ;
25+ readonly dryRun : boolean ;
26+ readonly interactive ?: boolean ;
27+ readonly runtimeStatePath ?: string ;
28+ } ,
2229) {
30+ yield * Console . log ( `CLI: Node ${ process . versions . node } (${ process . execPath } )` ) ;
31+ if ( options . runtimeStatePath !== undefined ) {
32+ const state = yield * readPersistedServerRuntimeState ( options . runtimeStatePath ) ;
33+ if ( Option . isSome ( state ) && isProcessAlive ( state . value . pid ) ) {
34+ const runtime = state . value ;
35+ yield * Console . log (
36+ runtime . nodeVersion === undefined
37+ ? "Server: Node runtime not recorded by this release."
38+ : `Server: Node ${ runtime . nodeVersion } (${ runtime . executablePath ?? "executable not recorded" } ; pid ${ String ( runtime . pid ) } )` ,
39+ ) ;
40+ if ( runtime . serviceManaged === true ) {
41+ const launcher = runtime . launcherRuntime ;
42+ yield * Console . log (
43+ launcher === undefined
44+ ? "Service launcher: Node runtime not recorded. Reinstall the service with the updated CLI to replace an older launcher."
45+ : isProcessAlive ( launcher . pid )
46+ ? `Service launcher: Node ${ launcher . nodeVersion } (${ launcher . executablePath } ; pid ${ String ( launcher . pid ) } )`
47+ : "Service launcher: recorded process is no longer running." ,
48+ ) ;
49+ }
50+ } else {
51+ yield * Console . log ( "Server: no running process recorded for this T3 home." ) ;
52+ }
53+ }
2354 const maintenance = yield * DatabaseMaintenance . DatabaseMaintenance ;
2455 const status = yield * maintenance . inspect ( databasePath ) ;
2556 yield * Console . log (
@@ -142,9 +173,11 @@ export const doctorCommand = Command.make("doctor", {
142173 Effect . gen ( function * ( ) {
143174 const logLevel = yield * GlobalFlag . LogLevel ;
144175 const config = yield * resolveCliAuthConfig ( flags , logLevel ) ;
145- yield * runDoctor ( config . dbPath , { fix : flags . fix , dryRun : flags . dryRun } ) . pipe (
146- Effect . provide ( Layer . merge ( DatabaseMaintenance . layer , CliService . layer ( config ) ) ) ,
147- ) ;
176+ yield * runDoctor ( config . dbPath , {
177+ fix : flags . fix ,
178+ dryRun : flags . dryRun ,
179+ runtimeStatePath : config . serverRuntimeStatePath ,
180+ } ) . pipe ( Effect . provide ( Layer . merge ( DatabaseMaintenance . layer , CliService . layer ( config ) ) ) ) ;
148181 } ) ,
149182 ) ,
150183) ;
0 commit comments