Skip to content

Commit

Permalink
chore: Improve service startup reliability
Browse files Browse the repository at this point in the history
  • Loading branch information
microshine committed May 24, 2024
1 parent 33e3a16 commit ab6da83
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,27 @@ export async function installGoodKey(distDir: string, systemDir: string) {

// Install service
await execAsync(`sc create gksvc binPath= "${path.join(systemDir, serviceFile)}" start= auto`);
await execAsync(`sc start gksvc`);

// Wait for the service to start
let isRunning = false;
let attempts = 0;
const maxAttempts = 10; // Maximum number of attempts
const interval = 400; // Interval between checks in milliseconds

while (!isRunning && attempts < maxAttempts) {
const { stdout } = await execAsync(`sc query gksvc`);
isRunning = stdout.includes('RUNNING');
if (!isRunning) {
// Wait for a second before checking again
await new Promise(resolve => setTimeout(resolve, interval));
}
attempts++;
}

if (!isRunning) {
throw new Error('Service did not start within the expected time.');
}

// Get User status using `gkutils auth status` and log it
const { stdout } = await execAsync(`${path.join(systemDir, utilFile)} auth status`);
Expand Down

0 comments on commit ab6da83

Please sign in to comment.