mirror of
https://github.com/pockethost/pockethost.git
synced 2025-03-30 15:08:30 +00:00
feat(pockethost): stop all Docker containers before running edge daemon
This commit is contained in:
parent
89b827c5d8
commit
21c663fe73
@ -1,3 +1,4 @@
|
||||
import Dockerode from 'dockerode'
|
||||
import { ErrorRequestHandler } from 'express'
|
||||
import { LoggerService } from '../../../../../common'
|
||||
import {
|
||||
@ -8,6 +9,7 @@ import {
|
||||
tryFetch,
|
||||
} from '../../../../../core'
|
||||
import {
|
||||
DOCKER_INSTANCE_IMAGE_NAME,
|
||||
MothershipAdminClientService,
|
||||
PocketbaseService,
|
||||
PortService,
|
||||
@ -21,6 +23,22 @@ export async function daemon() {
|
||||
const { dbg, error, info, warn } = logger
|
||||
info(`Starting`)
|
||||
|
||||
const docker = new Dockerode()
|
||||
|
||||
// Stop all running containers
|
||||
info(`Stopping all running Docker containers`)
|
||||
const containers = await docker.listContainers({ all: true })
|
||||
await Promise.all(
|
||||
containers.map(async (container) => {
|
||||
if (
|
||||
container.State === 'running' &&
|
||||
container.Image === DOCKER_INSTANCE_IMAGE_NAME
|
||||
) {
|
||||
await docker.getContainer(container.Id).stop()
|
||||
}
|
||||
}),
|
||||
)
|
||||
|
||||
await PortService({})
|
||||
await PocketbaseService({})
|
||||
|
||||
|
@ -47,7 +47,7 @@ export type PocketbaseProcess = {
|
||||
exitCode: Promise<number>
|
||||
}
|
||||
|
||||
const INSTANCE_IMAGE_NAME = `benallfree/pockethost-instance`
|
||||
export const DOCKER_INSTANCE_IMAGE_NAME = `benallfree/pockethost-instance`
|
||||
|
||||
export const createPocketbaseService = async (
|
||||
config: PocketbaseServiceConfig,
|
||||
@ -141,7 +141,7 @@ export const createPocketbaseService = async (
|
||||
}
|
||||
|
||||
const createOptions: ContainerCreateOptions = {
|
||||
Image: INSTANCE_IMAGE_NAME,
|
||||
Image: DOCKER_INSTANCE_IMAGE_NAME,
|
||||
Env: map(
|
||||
{
|
||||
...env,
|
||||
@ -194,7 +194,7 @@ export const createPocketbaseService = async (
|
||||
|
||||
const emitter = docker
|
||||
.run(
|
||||
INSTANCE_IMAGE_NAME,
|
||||
DOCKER_INSTANCE_IMAGE_NAME,
|
||||
[''], // Supplied by createOptions
|
||||
[stdout, stderr],
|
||||
createOptions,
|
||||
|
Loading…
x
Reference in New Issue
Block a user