Skip to content

Commit 80c45ee

Browse files
authored
Merge pull request #30 from useblacksmith/pb/exit-on-double
feat: refuse to start if another buildkitd process is detected
2 parents 2240731 + 8fc702d commit 80c45ee

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,25 @@ async function startBlacksmithBuilder(
206206
// Get CPU count for parallelism
207207
const parallelism = await getNumCPUs();
208208

209+
// Check if buildkitd is already running before starting
210+
try {
211+
const { stdout } = await execAsync("pgrep buildkitd");
212+
if (stdout.trim()) {
213+
throw new Error(
214+
`Detected existing buildkitd process (PID: ${stdout.trim()}). Refusing to start to avoid conflicts.`,
215+
);
216+
}
217+
} catch (error) {
218+
if ((error as { code?: number }).code !== 1) {
219+
// pgrep returns exit code 1 when no process found, which is what we want
220+
// Any other error code indicates a real problem
221+
throw new Error(
222+
`Failed to check for existing buildkitd process: ${(error as Error).message}`,
223+
);
224+
}
225+
// Exit code 1 means no buildkitd process found, which is good - we can proceed
226+
}
227+
209228
// Start buildkitd
210229
const buildkitdStartTime = Date.now();
211230
const buildkitdAddr = await startAndConfigureBuildkitd(

0 commit comments

Comments
 (0)