-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathshell.ts
48 lines (43 loc) · 1.12 KB
/
shell.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { exec } from 'child_process'
import { delay } from '../src/utils/index'
const LOGGING = !!process.env.LOGSHELL
function sh(cmd: string) {
return new Promise<void>((resolve, reject) => {
const cp = exec(cmd, (err, stdout, stderr) => {
if (stdout && LOGGING) {
console.log(`[${cp.pid}] stdout:`)
console.log(stdout)
}
if (stderr && LOGGING) {
console.log(`[${cp.pid}] stderr:`)
console.log(stderr)
}
if (err) {
reject(err)
} else {
resolve()
}
})
console.log(`[${cp.pid}] ${cmd}`)
})
}
export async function upRedisServer(num: number) {
const port = 6000 + num
await sh(
`docker compose up -d redis${num} && yarn wait-for --redis redis://127.0.0.1:${port}`
)
}
export async function downRedisServer(num: number) {
const port = 6000 + num
await sh(`docker compose stop redis${num}`)
let tries = 0
while (true) {
try {
console.log(`wait server${num} shut down... ${++tries}`)
await sh(`yarn wait-for --redis redis://127.0.0.1:${port} -c 1`)
await delay(100)
} catch {
break
}
}
}