@open-mercato/cli 0.11.1-develop.8883.1.78d3645a50 → 0.11.1-develop.8920.1.d3c2cc4681
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +7 -1
- package/dist/agentic/guides/integrations.md +1 -1
- package/dist/agentic/guides/module-facts.json +2106 -181
- package/dist/agentic/guides/module-facts.v2.json +2106 -181
- package/dist/agentic/guides/modules/agent_orchestrator/index.md +1 -1
- package/dist/agentic/guides/modules/ai_assistant/index.md +1 -1
- package/dist/agentic/guides/modules/api_docs/index.md +1 -1
- package/dist/agentic/guides/modules/api_keys/index.md +1 -1
- package/dist/agentic/guides/modules/assisted_selling/index.md +1 -1
- package/dist/agentic/guides/modules/attachments/index.md +1 -1
- package/dist/agentic/guides/modules/audit_logs/index.md +1 -1
- package/dist/agentic/guides/modules/auth/index.md +1 -1
- package/dist/agentic/guides/modules/availability/index.md +1 -1
- package/dist/agentic/guides/modules/backups/index.md +1 -1
- package/dist/agentic/guides/modules/business_rules/index.md +1 -1
- package/dist/agentic/guides/modules/carrier_inpost/index.md +1 -1
- package/dist/agentic/guides/modules/cart/index.md +1 -1
- package/dist/agentic/guides/modules/catalog/acl-features.md +3 -1
- package/dist/agentic/guides/modules/catalog/backend-pages.md +3 -0
- package/dist/agentic/guides/modules/catalog/contribution-resolutions.md +4 -0
- package/dist/agentic/guides/modules/catalog/custom-entities.md +1 -0
- package/dist/agentic/guides/modules/catalog/domain-commands.md +3 -1
- package/dist/agentic/guides/modules/catalog/entities.md +3 -0
- package/dist/agentic/guides/modules/catalog/events.md +4 -1
- package/dist/agentic/guides/modules/catalog/exact-override-targets.md +5 -0
- package/dist/agentic/guides/modules/catalog/host-extension-points.md +1 -1
- package/dist/agentic/guides/modules/catalog/index.md +6 -6
- package/dist/agentic/guides/modules/catalog/search-entities.md +1 -0
- package/dist/agentic/guides/modules/catalog/umes-contributions.md +4 -0
- package/dist/agentic/guides/modules/catalog/umes-hosts.md +8 -0
- package/dist/agentic/guides/modules/channel_apns/index.md +1 -1
- package/dist/agentic/guides/modules/channel_discord/index.md +1 -1
- package/dist/agentic/guides/modules/channel_expo/index.md +1 -1
- package/dist/agentic/guides/modules/channel_fcm/index.md +1 -1
- package/dist/agentic/guides/modules/channel_gmail/index.md +1 -1
- package/dist/agentic/guides/modules/channel_imap/index.md +1 -1
- package/dist/agentic/guides/modules/channel_ms365/acl-features.md +12 -0
- package/dist/agentic/guides/modules/channel_ms365/contribution-resolutions.md +12 -0
- package/dist/agentic/guides/modules/channel_ms365/di-registrations-rich.md +12 -0
- package/dist/agentic/guides/modules/channel_ms365/exact-override-targets.md +17 -0
- package/dist/agentic/guides/modules/channel_ms365/index.md +18 -0
- package/dist/agentic/guides/modules/channel_ms365/owned-contract-module-metadata.md +11 -0
- package/dist/agentic/guides/modules/channel_ms365/setup.md +11 -0
- package/dist/agentic/guides/modules/channel_ms365/umes-contributions.md +12 -0
- package/dist/agentic/guides/modules/channel_resend/index.md +1 -1
- package/dist/agentic/guides/modules/channel_ses/index.md +1 -1
- package/dist/agentic/guides/modules/channel_smtp/index.md +1 -1
- package/dist/agentic/guides/modules/checkout/exact-override-targets.md +1 -1
- package/dist/agentic/guides/modules/checkout/index.md +1 -1
- package/dist/agentic/guides/modules/checkout/workers.md +1 -1
- package/dist/agentic/guides/modules/communication_channels/incoming-installed-contributions.md +1 -0
- package/dist/agentic/guides/modules/communication_channels/index.md +2 -2
- package/dist/agentic/guides/modules/configs/acl-features.md +3 -1
- package/dist/agentic/guides/modules/configs/backend-pages.md +1 -0
- package/dist/agentic/guides/modules/configs/exact-override-targets.md +3 -0
- package/dist/agentic/guides/modules/configs/index.md +3 -3
- package/dist/agentic/guides/modules/configs/owned-contract-module-metadata.md +1 -1
- package/dist/agentic/guides/modules/configs/umes-hosts.md +1 -0
- package/dist/agentic/guides/modules/content/index.md +1 -1
- package/dist/agentic/guides/modules/currencies/index.md +1 -1
- package/dist/agentic/guides/modules/customer_accounts/index.md +1 -1
- package/dist/agentic/guides/modules/customer_groups/index.md +1 -1
- package/dist/agentic/guides/modules/customers/incoming-installed-contributions.md +1 -0
- package/dist/agentic/guides/modules/customers/index.md +1 -1
- package/dist/agentic/guides/modules/dashboards/index.md +1 -1
- package/dist/agentic/guides/modules/data_sync/index.md +1 -1
- package/dist/agentic/guides/modules/design_system/index.md +1 -1
- package/dist/agentic/guides/modules/devices/index.md +1 -1
- package/dist/agentic/guides/modules/dictionaries/index.md +1 -1
- package/dist/agentic/guides/modules/directory/index.md +1 -1
- package/dist/agentic/guides/modules/documents/index.md +1 -1
- package/dist/agentic/guides/modules/ecommerce/index.md +1 -1
- package/dist/agentic/guides/modules/entities/index.md +1 -1
- package/dist/agentic/guides/modules/eudr/index.md +1 -1
- package/dist/agentic/guides/modules/events/index.md +1 -1
- package/dist/agentic/guides/modules/feature_toggles/index.md +1 -1
- package/dist/agentic/guides/modules/forms/index.md +1 -1
- package/dist/agentic/guides/modules/gateway_autopay/index.md +1 -1
- package/dist/agentic/guides/modules/gateway_stripe/index.md +1 -1
- package/dist/agentic/guides/modules/gateway_tpay/index.md +1 -1
- package/dist/agentic/guides/modules/generators/index.md +1 -1
- package/dist/agentic/guides/modules/gus_regon/acl-features.md +11 -0
- package/dist/agentic/guides/modules/gus_regon/cli-commands.md +12 -0
- package/dist/agentic/guides/modules/gus_regon/contribution-resolutions.md +11 -0
- package/dist/agentic/guides/modules/gus_regon/di-registrations-rich.md +11 -0
- package/dist/agentic/guides/modules/gus_regon/exact-override-targets.md +17 -0
- package/dist/agentic/guides/modules/gus_regon/index.md +19 -0
- package/dist/agentic/guides/modules/gus_regon/owned-contract-module-metadata.md +11 -0
- package/dist/agentic/guides/modules/gus_regon/setup.md +11 -0
- package/dist/agentic/guides/modules/gus_regon/umes-contributions.md +11 -0
- package/dist/agentic/guides/modules/inbox_ops/index.md +1 -1
- package/dist/agentic/guides/modules/integrations/index.md +1 -1
- package/dist/agentic/guides/modules/ledger/index.md +1 -1
- package/dist/agentic/guides/modules/maintenance/index.md +1 -1
- package/dist/agentic/guides/modules/messages/index.md +1 -1
- package/dist/agentic/guides/modules/notifications/index.md +1 -1
- package/dist/agentic/guides/modules/onboarding/index.md +1 -1
- package/dist/agentic/guides/modules/payment_gateways/index.md +1 -1
- package/dist/agentic/guides/modules/perspectives/index.md +1 -1
- package/dist/agentic/guides/modules/phone_calls/index.md +1 -1
- package/dist/agentic/guides/modules/planner/index.md +1 -1
- package/dist/agentic/guides/modules/portal/index.md +1 -1
- package/dist/agentic/guides/modules/progress/index.md +1 -1
- package/dist/agentic/guides/modules/promotions/index.md +1 -1
- package/dist/agentic/guides/modules/push_notifications/index.md +1 -1
- package/dist/agentic/guides/modules/query_index/index.md +1 -1
- package/dist/agentic/guides/modules/record_locks/index.md +1 -1
- package/dist/agentic/guides/modules/resources/index.md +1 -1
- package/dist/agentic/guides/modules/sales/index.md +1 -1
- package/dist/agentic/guides/modules/sales_invoices_gl_posting/index.md +1 -1
- package/dist/agentic/guides/modules/scheduler/index.md +1 -1
- package/dist/agentic/guides/modules/search/index.md +1 -1
- package/dist/agentic/guides/modules/security/index.md +1 -1
- package/dist/agentic/guides/modules/seeds/index.md +1 -1
- package/dist/agentic/guides/modules/shipping_carriers/index.md +1 -1
- package/dist/agentic/guides/modules/sso/index.md +1 -1
- package/dist/agentic/guides/modules/staff/index.md +1 -1
- package/dist/agentic/guides/modules/storage_s3/index.md +1 -1
- package/dist/agentic/guides/modules/sync_akeneo/index.md +1 -1
- package/dist/agentic/guides/modules/sync_excel/index.md +1 -1
- package/dist/agentic/guides/modules/sync_shopify/acl-features.md +12 -0
- package/dist/agentic/guides/modules/sync_shopify/cli-commands.md +12 -0
- package/dist/agentic/guides/modules/sync_shopify/contribution-resolutions.md +11 -0
- package/dist/agentic/guides/modules/sync_shopify/di-registrations-rich.md +11 -0
- package/dist/agentic/guides/modules/sync_shopify/exact-override-targets.md +17 -0
- package/dist/agentic/guides/modules/sync_shopify/index.md +19 -0
- package/dist/agentic/guides/modules/sync_shopify/owned-contract-module-metadata.md +11 -0
- package/dist/agentic/guides/modules/sync_shopify/setup.md +11 -0
- package/dist/agentic/guides/modules/sync_shopify/umes-contributions.md +11 -0
- package/dist/agentic/guides/modules/system_status_overlays/index.md +1 -1
- package/dist/agentic/guides/modules/telemetry/index.md +1 -1
- package/dist/agentic/guides/modules/tillio/index.md +1 -1
- package/dist/agentic/guides/modules/translations/index.md +1 -1
- package/dist/agentic/guides/modules/upgrade_actions/index.md +1 -1
- package/dist/agentic/guides/modules/warranty_claims/index.md +1 -1
- package/dist/agentic/guides/modules/webhooks/index.md +1 -1
- package/dist/agentic/guides/modules/wms/index.md +1 -1
- package/dist/agentic/guides/modules/workflows/index.md +1 -1
- package/dist/agentic/guides/reference-module-facts.json +2 -2
- package/dist/agentic/guides/reference-modules/example/index.md +1 -1
- package/dist/agentic/guides/upstream/BACKWARD_COMPATIBILITY.md +18 -0
- package/dist/agentic/guides/upstream/manifest.json +2 -2
- package/dist/agentic/shared/ai/harness/cases.json +4 -3
- package/dist/agentic/shared/ai/skills/om-integration-builder/references/provider-families.md +1 -1
- package/dist/lib/init-secrets.js +1 -1
- package/dist/lib/init-secrets.js.map +2 -2
- package/dist/lib/server-start-lock.js +120 -21
- package/dist/lib/server-start-lock.js.map +2 -2
- package/dist/lib/testing/integration-discovery.js +13 -0
- package/dist/lib/testing/integration-discovery.js.map +2 -2
- package/dist/lib/testing/integration.js +286 -26
- package/dist/lib/testing/integration.js.map +2 -2
- package/dist/mercato.js +9 -2
- package/dist/mercato.js.map +2 -2
- package/package.json +7 -7
- package/src/__tests__/mercato.test.ts +68 -0
- package/src/lib/__tests__/init-secrets.test.ts +11 -2
- package/src/lib/__tests__/server-start-lock.test.ts +400 -0
- package/src/lib/generators/__tests__/module-facts.extension-hosts.test.ts +2 -0
- package/src/lib/init-secrets.ts +1 -1
- package/src/lib/server-start-lock.ts +170 -19
- package/src/lib/testing/__tests__/integration-prebuilt-artifacts.test.ts +486 -0
- package/src/lib/testing/__tests__/integration.test.ts +27 -0
- package/src/lib/testing/integration-discovery.ts +16 -0
- package/src/lib/testing/integration.ts +366 -27
- package/src/mercato.ts +9 -2
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto'
|
|
1
2
|
import fs from 'node:fs'
|
|
2
3
|
import path from 'node:path'
|
|
3
4
|
|
|
@@ -5,6 +6,9 @@ type ServerStartLockRecord = {
|
|
|
5
6
|
pid: number
|
|
6
7
|
port: string | null
|
|
7
8
|
startedAt: string
|
|
9
|
+
processStartTime: string | null
|
|
10
|
+
bootId: string | null
|
|
11
|
+
token: string | null
|
|
8
12
|
}
|
|
9
13
|
|
|
10
14
|
export type ServerStartLockHandle = {
|
|
@@ -12,9 +16,28 @@ export type ServerStartLockHandle = {
|
|
|
12
16
|
release: () => void
|
|
13
17
|
}
|
|
14
18
|
|
|
15
|
-
|
|
19
|
+
const BOOT_ID_PATH = '/proc/sys/kernel/random/boot_id'
|
|
20
|
+
const STAT_FIRST_FIELD_AFTER_COMMAND = 3
|
|
21
|
+
const STAT_START_TIME_FIELD = 22
|
|
22
|
+
const TAKEOVER_BUSY_WAIT_MS = 25
|
|
23
|
+
const MAX_TAKEOVER_ATTEMPTS = 400
|
|
24
|
+
|
|
25
|
+
function readOptionalString(value: unknown): string | null {
|
|
26
|
+
return typeof value === 'string' && value.trim().length > 0 ? value.trim() : null
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function readRawFile(filePath: string): string | null {
|
|
30
|
+
try {
|
|
31
|
+
return fs.readFileSync(filePath, 'utf8')
|
|
32
|
+
} catch (error) {
|
|
33
|
+
if ((error as NodeJS.ErrnoException).code === 'ENOENT') return null
|
|
34
|
+
throw error
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function parseServerStartLock(raw: string | null): ServerStartLockRecord | null {
|
|
39
|
+
if (raw === null) return null
|
|
16
40
|
try {
|
|
17
|
-
const raw = fs.readFileSync(lockPath, 'utf8')
|
|
18
41
|
const parsed = JSON.parse(raw) as Partial<ServerStartLockRecord>
|
|
19
42
|
if (typeof parsed.pid !== 'number' || !Number.isInteger(parsed.pid) || parsed.pid <= 0) {
|
|
20
43
|
return null
|
|
@@ -23,12 +46,42 @@ function readServerStartLock(lockPath: string): ServerStartLockRecord | null {
|
|
|
23
46
|
pid: parsed.pid,
|
|
24
47
|
port: typeof parsed.port === 'string' && parsed.port.trim().length > 0 ? parsed.port : null,
|
|
25
48
|
startedAt: typeof parsed.startedAt === 'string' ? parsed.startedAt : '',
|
|
49
|
+
processStartTime: readOptionalString(parsed.processStartTime),
|
|
50
|
+
bootId: readOptionalString(parsed.bootId),
|
|
51
|
+
token: readOptionalString(parsed.token),
|
|
26
52
|
}
|
|
27
53
|
} catch {
|
|
28
54
|
return null
|
|
29
55
|
}
|
|
30
56
|
}
|
|
31
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Reads the start time of `pid` (field 22 of `/proc/<pid>/stat`). The command name
|
|
60
|
+
* in field 2 may contain spaces or parentheses, so only the text after the last `)`
|
|
61
|
+
* is split. Returns `null` when the platform has no `/proc` (macOS, Windows) or the
|
|
62
|
+
* entry cannot be read or parsed.
|
|
63
|
+
*/
|
|
64
|
+
export function readProcessStartTime(pid: number): string | null {
|
|
65
|
+
try {
|
|
66
|
+
const stat = fs.readFileSync(`/proc/${pid}/stat`, 'utf8')
|
|
67
|
+
const commandEnd = stat.lastIndexOf(')')
|
|
68
|
+
if (commandEnd < 0) return null
|
|
69
|
+
const fields = stat.slice(commandEnd + 1).trim().split(/\s+/)
|
|
70
|
+
const startTime = fields[STAT_START_TIME_FIELD - STAT_FIRST_FIELD_AFTER_COMMAND]
|
|
71
|
+
return startTime && /^\d+$/.test(startTime) ? startTime : null
|
|
72
|
+
} catch {
|
|
73
|
+
return null
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function readBootId(): string | null {
|
|
78
|
+
try {
|
|
79
|
+
return readOptionalString(fs.readFileSync(BOOT_ID_PATH, 'utf8'))
|
|
80
|
+
} catch {
|
|
81
|
+
return null
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
32
85
|
function isProcessAlive(pid: number): boolean {
|
|
33
86
|
try {
|
|
34
87
|
process.kill(pid, 0)
|
|
@@ -38,6 +91,98 @@ function isProcessAlive(pid: number): boolean {
|
|
|
38
91
|
}
|
|
39
92
|
}
|
|
40
93
|
|
|
94
|
+
/**
|
|
95
|
+
* A lock is held only while the process that wrote it is still running. A live pid
|
|
96
|
+
* alone is not enough: the lock file sits in the app directory and survives a
|
|
97
|
+
* container restart, while pid numbering starts again, so the recorded pid soon
|
|
98
|
+
* belongs to an unrelated process. When the lock carries the boot id and the
|
|
99
|
+
* process start time, both must still match. When either side cannot be read
|
|
100
|
+
* (old lock format, no `/proc`), the pid check alone decides, as before.
|
|
101
|
+
*/
|
|
102
|
+
function isLockOwnerAlive(lock: ServerStartLockRecord): boolean {
|
|
103
|
+
if (!isProcessAlive(lock.pid)) return false
|
|
104
|
+
|
|
105
|
+
if (lock.bootId) {
|
|
106
|
+
const currentBootId = readBootId()
|
|
107
|
+
if (currentBootId && currentBootId !== lock.bootId) return false
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (lock.processStartTime) {
|
|
111
|
+
const currentStartTime = readProcessStartTime(lock.pid)
|
|
112
|
+
if (currentStartTime && currentStartTime !== lock.processStartTime) return false
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return true
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Treats a record written by this very pid as dead: this process never holds a
|
|
120
|
+
* lock or a takeover guard while it inspects one, so a matching pid can only come
|
|
121
|
+
* from a previous run (pid numbering restarts with the container).
|
|
122
|
+
*/
|
|
123
|
+
function isHeldByAnotherLiveProcess(record: ServerStartLockRecord | null): record is ServerStartLockRecord {
|
|
124
|
+
return record !== null && record.pid !== process.pid && isLockOwnerAlive(record)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Creates `target` with `content` only if it does not exist yet. The content is
|
|
129
|
+
* written to a private temporary file first and hard-linked into place, so other
|
|
130
|
+
* processes never observe a half-written file. Returns `false` when `target`
|
|
131
|
+
* already exists.
|
|
132
|
+
*/
|
|
133
|
+
function publishExclusive(target: string, content: string): boolean {
|
|
134
|
+
const tempPath = `${target}.${process.pid}.${randomUUID()}.tmp`
|
|
135
|
+
fs.writeFileSync(tempPath, content, { encoding: 'utf8', flag: 'wx' })
|
|
136
|
+
try {
|
|
137
|
+
fs.linkSync(tempPath, target)
|
|
138
|
+
return true
|
|
139
|
+
} catch (error) {
|
|
140
|
+
if ((error as NodeJS.ErrnoException).code === 'EEXIST') return false
|
|
141
|
+
throw error
|
|
142
|
+
} finally {
|
|
143
|
+
fs.rmSync(tempPath, { force: true })
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function sleepSync(ms: number): void {
|
|
148
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Removes the stale lock generation `staleRaw` unless another process has already
|
|
153
|
+
* replaced it. Several starts can inspect the same stale lock at once, and a plain
|
|
154
|
+
* unlink would let a late one delete the lock a faster one has just written. Only
|
|
155
|
+
* the process that exclusively creates the takeover guard for this generation may
|
|
156
|
+
* remove it, and it re-reads the lock under the guard first. A guard left behind
|
|
157
|
+
* by a process that died mid-takeover is skipped in favour of the next slot.
|
|
158
|
+
*
|
|
159
|
+
* Returns `false` when a live process holds the guard and the caller must retry.
|
|
160
|
+
*/
|
|
161
|
+
function removeStaleGeneration(lockPath: string, staleRaw: string, ownRaw: string): boolean {
|
|
162
|
+
const generation = createHash('sha256').update(staleRaw).digest('hex').slice(0, 16)
|
|
163
|
+
const skippedGuards: string[] = []
|
|
164
|
+
let ownedGuard: string | null = null
|
|
165
|
+
try {
|
|
166
|
+
for (let slot = 0; ; slot += 1) {
|
|
167
|
+
const guardPath = `${lockPath}.${generation}.${slot}.takeover`
|
|
168
|
+
if (publishExclusive(guardPath, ownRaw)) {
|
|
169
|
+
ownedGuard = guardPath
|
|
170
|
+
break
|
|
171
|
+
}
|
|
172
|
+
const guardRaw = readRawFile(guardPath)
|
|
173
|
+
if (guardRaw === null || isHeldByAnotherLiveProcess(parseServerStartLock(guardRaw))) return false
|
|
174
|
+
skippedGuards.push(guardPath)
|
|
175
|
+
}
|
|
176
|
+
if (readRawFile(lockPath) === staleRaw) {
|
|
177
|
+
fs.rmSync(lockPath, { force: true })
|
|
178
|
+
}
|
|
179
|
+
for (const guardPath of skippedGuards) fs.rmSync(guardPath, { force: true })
|
|
180
|
+
return true
|
|
181
|
+
} finally {
|
|
182
|
+
if (ownedGuard !== null) fs.rmSync(ownedGuard, { force: true })
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
41
186
|
export function getServerStartLockPath(appDir: string): string {
|
|
42
187
|
return path.join(appDir, '.mercato', 'server-start.lock')
|
|
43
188
|
}
|
|
@@ -51,29 +196,33 @@ export function acquireServerStartLock(
|
|
|
51
196
|
pid: process.pid,
|
|
52
197
|
port: typeof options.port === 'string' && options.port.trim().length > 0 ? options.port.trim() : null,
|
|
53
198
|
startedAt: new Date().toISOString(),
|
|
199
|
+
processStartTime: readProcessStartTime(process.pid),
|
|
200
|
+
bootId: readBootId(),
|
|
201
|
+
token: randomUUID(),
|
|
54
202
|
}
|
|
203
|
+
const ownRaw = JSON.stringify(lockRecord)
|
|
55
204
|
|
|
56
205
|
fs.mkdirSync(path.dirname(lockPath), { recursive: true })
|
|
57
206
|
|
|
58
|
-
for (
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
207
|
+
for (let attempt = 0; !publishExclusive(lockPath, ownRaw); attempt += 1) {
|
|
208
|
+
const existingRaw = readRawFile(lockPath)
|
|
209
|
+
if (existingRaw === null) continue
|
|
210
|
+
|
|
211
|
+
const existingLock = parseServerStartLock(existingRaw)
|
|
212
|
+
if (isHeldByAnotherLiveProcess(existingLock)) {
|
|
213
|
+
const portSuffix = existingLock.port ? ` on port ${existingLock.port}` : ''
|
|
214
|
+
throw new Error(
|
|
215
|
+
`[server] Another Open Mercato production server is already running for ${appDir} (pid ${existingLock.pid}${portSuffix}). Stop it before starting another instance.`,
|
|
216
|
+
)
|
|
217
|
+
}
|
|
67
218
|
|
|
68
|
-
|
|
69
|
-
if (
|
|
70
|
-
const portSuffix = existingLock.port ? ` on port ${existingLock.port}` : ''
|
|
219
|
+
if (!removeStaleGeneration(lockPath, existingRaw, ownRaw)) {
|
|
220
|
+
if (attempt >= MAX_TAKEOVER_ATTEMPTS) {
|
|
71
221
|
throw new Error(
|
|
72
|
-
`[server] Another
|
|
222
|
+
`[server] Another process is still replacing the stale server start lock for ${appDir}. Try again.`,
|
|
73
223
|
)
|
|
74
224
|
}
|
|
75
|
-
|
|
76
|
-
fs.rmSync(lockPath, { force: true })
|
|
225
|
+
sleepSync(TAKEOVER_BUSY_WAIT_MS)
|
|
77
226
|
}
|
|
78
227
|
}
|
|
79
228
|
|
|
@@ -82,8 +231,10 @@ export function acquireServerStartLock(
|
|
|
82
231
|
if (released) return
|
|
83
232
|
released = true
|
|
84
233
|
|
|
85
|
-
|
|
86
|
-
if
|
|
234
|
+
// Compare the token, not the pid: after a takeover the file belongs to
|
|
235
|
+
// another process even if it reuses this pid in a later container run.
|
|
236
|
+
const currentLock = parseServerStartLock(readRawFile(lockPath))
|
|
237
|
+
if (currentLock?.token === lockRecord.token) {
|
|
87
238
|
fs.rmSync(lockPath, { force: true })
|
|
88
239
|
}
|
|
89
240
|
}
|