-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add vlmcsd plugin with conditional loading and process manage
- Loading branch information
Showing
3 changed files
with
50 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
NUXT_PUBLIC_API_URL=https://kms.ikxin.com | ||
NUXT_PUBLIC_I18N_BASE_URL=https://kms.ikxin.com | ||
ENABLE_VLMCSD=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { spawn } from 'child_process' | ||
import { join } from 'path' | ||
import { arch, platform } from 'os' | ||
import { existsSync } from 'fs' | ||
|
||
export default defineNitroPlugin(nitro => { | ||
if (process.env.ENABLE_VLMCSD !== 'true') { | ||
console.log('Vlmcsd is disabled') | ||
return | ||
} | ||
|
||
const vlmcsdPath = join( | ||
process.cwd(), | ||
'binaries', | ||
`vlmcsd-${platform()}-${arch()}` | ||
) | ||
|
||
if (!existsSync(vlmcsdPath)) { | ||
console.log('Vlmcsd binary not found') | ||
return | ||
} | ||
|
||
const vlmcsd = spawn(vlmcsdPath, ['-D'], { stdio: 'inherit' }) | ||
|
||
nitro.hooks.hookOnce('close', () => { | ||
vlmcsd.removeAllListeners() | ||
vlmcsd.kill() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,47 @@ | ||
export default defineTask({ | ||
meta: { | ||
name: "monitor", | ||
description: "Run KMS server monitoring.", | ||
name: 'monitor', | ||
description: 'Run KMS server monitoring.', | ||
}, | ||
async run() { | ||
const results = await Promise.all( | ||
monitorList.map(async (host) => { | ||
let monitorData = await storage.getItem<MonitorData[]>(`${host}.json`); | ||
monitorList.map(async host => { | ||
let monitorData = await storage.getItem<MonitorData[]>(`${host}.json`) | ||
|
||
if (!Array.isArray(monitorData)) { | ||
monitorData = []; | ||
monitorData = [] | ||
} | ||
|
||
if (monitorData.length >= 100) { | ||
monitorData.shift(); | ||
monitorData.shift() | ||
} | ||
|
||
const { status, delay } = await runVlmcs({ host }); | ||
const { status, delay } = await runVlmcs({ host }) | ||
|
||
monitorData.push({ | ||
status, | ||
time: Date.now(), | ||
delay, | ||
}); | ||
}) | ||
|
||
await storage.setItem<MonitorData[]>(`${host}.json`, monitorData); | ||
await storage.setItem<MonitorData[]>(`${host}.json`, monitorData) | ||
|
||
return { host, status }; | ||
return { host, status } | ||
}) | ||
); | ||
) | ||
|
||
const count = results.filter((item) => { | ||
const count = results.filter(item => { | ||
if (!item.status) { | ||
console.log("Monitor failed:", item.host); | ||
console.log('Monitor failed:', item.host) | ||
} | ||
return item.status; | ||
}).length; | ||
return item.status | ||
}).length | ||
|
||
console.log( | ||
new Date().toISOString(), | ||
`Monitor task completed, successful: ${count}` | ||
); | ||
) | ||
|
||
return { result: "Done" }; | ||
return { result: 'Done' } | ||
}, | ||
}); | ||
}) |