Skip to content

Commit 6ef193f

Browse files
committed
chore: wip
1 parent 48d3a46 commit 6ef193f

File tree

4 files changed

+60
-1
lines changed

4 files changed

+60
-1
lines changed

packages/launchpad/src/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export const defaultConfig: LaunchpadConfig = {
7575
startupTimeout: Number.parseInt(process.env.LAUNCHPAD_SERVICES_STARTUP_TIMEOUT || '30', 10),
7676
shutdownTimeout: Number.parseInt(process.env.LAUNCHPAD_SERVICES_SHUTDOWN_TIMEOUT || '10', 10),
7777
infer: process.env.LAUNCHPAD_SERVICES_INFER !== 'false',
78+
shouldAutoStart: process.env.LAUNCHPAD_SERVICES_SHOULD_AUTOSTART !== 'false',
7879
database: {
7980
username: process.env.LAUNCHPAD_DB_USERNAME || 'root',
8081
password: process.env.LAUNCHPAD_DB_PASSWORD || 'password',

packages/launchpad/src/services/platform.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ export function generateLaunchdPlist(service: ServiceInstance): LaunchdPlist {
4949
// Compute runtime PATH and dynamic library search paths for packages started by launchd
5050
// launchd does not inherit shell env, so we must include env-specific paths here.
5151
const envVars: Record<string, string> = {}
52+
// Determine auto-start preference: env override > config > service.enabled
53+
const envAutoStart = process.env.LAUNCHPAD_SERVICES_SHOULD_AUTOSTART
54+
const shouldAutoStartEffective
55+
= envAutoStart !== undefined
56+
? (envAutoStart !== 'false')
57+
: ((config.services && 'shouldAutoStart' in config.services)
58+
? Boolean(config.services.shouldAutoStart)
59+
: Boolean(service.enabled))
5260

5361
try {
5462
const binDir = path.dirname(executablePath)
@@ -139,7 +147,7 @@ export function generateLaunchdPlist(service: ServiceInstance): LaunchdPlist {
139147
},
140148
StandardOutPath: service.logFile || path.join(logDir || '', `${definition.name || service.name}.log`),
141149
StandardErrorPath: service.logFile || path.join(logDir || '', `${definition.name || service.name}.log`),
142-
RunAtLoad: service.enabled || false,
150+
RunAtLoad: shouldAutoStartEffective,
143151
KeepAlive: { SuccessfulExit: false },
144152
UserName: process.env.USER || 'root',
145153
}

packages/launchpad/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export interface LaunchpadConfig {
8787
services?: {
8888
enabled?: boolean
8989
autoStart?: boolean
90+
shouldAutoStart?: boolean
9091
dataDir?: string
9192
logDir?: string
9293
configDir?: string
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import type { ServiceInstance } from '../src/types'
2+
import { describe, expect, it } from 'bun:test'
3+
import { generateLaunchdPlist } from '../src/services/platform'
4+
5+
function makeServiceInstance(name: string, overrides: Partial<ServiceInstance> = {}): ServiceInstance {
6+
return {
7+
name,
8+
status: 'stopped',
9+
enabled: false,
10+
definition: {
11+
name,
12+
displayName: name,
13+
packageDomain: 'example.org',
14+
executable: 'dummy',
15+
args: [],
16+
dataDirectory: '/tmp',
17+
pidFile: '/tmp/d.pid',
18+
port: 1234,
19+
dependencies: [],
20+
healthCheck: { command: ['true'], expectedExitCode: 0, timeout: 1, interval: 1, retries: 1 },
21+
},
22+
...overrides,
23+
} as unknown as ServiceInstance
24+
}
25+
26+
describe('services.shouldAutoStart → launchd RunAtLoad', () => {
27+
it('RunAtLoad=false when shouldAutoStart=false', async () => {
28+
process.env.LAUNCHPAD_SERVICES_SHOULD_AUTOSTART = 'false'
29+
const svc = makeServiceInstance('redis')
30+
const plist = generateLaunchdPlist(svc)
31+
expect(plist.RunAtLoad).toBe(false)
32+
delete process.env.LAUNCHPAD_SERVICES_SHOULD_AUTOSTART
33+
})
34+
35+
it('RunAtLoad=true when shouldAutoStart=true', async () => {
36+
process.env.LAUNCHPAD_SERVICES_SHOULD_AUTOSTART = 'true'
37+
const svc = makeServiceInstance('postgres')
38+
const plist = generateLaunchdPlist(svc)
39+
expect(plist.RunAtLoad).toBe(true)
40+
delete process.env.LAUNCHPAD_SERVICES_SHOULD_AUTOSTART
41+
})
42+
43+
it('RunAtLoad defaults to service.enabled when shouldAutoStart not set', async () => {
44+
delete process.env.LAUNCHPAD_SERVICES_SHOULD_AUTOSTART
45+
const svc = makeServiceInstance('postgres', { enabled: true })
46+
const plist = generateLaunchdPlist(svc)
47+
expect(plist.RunAtLoad).toBe(true)
48+
})
49+
})

0 commit comments

Comments
 (0)