Add upgrade mode support

This commit is contained in:
Ben Allfree 2023-12-30 15:49:50 +00:00
parent cd49c81fd4
commit da8831a9f7
2 changed files with 18 additions and 7 deletions

View File

@ -30,6 +30,8 @@ export const _IS_DEV = process.env.NODE_ENV === 'development'
console.log({ _PH_HOME, _PH_PROJECT_ROOT, _PH_BUILD_ROOT })
export const SETTINGS = {
UPGRADE_MODE: mkBoolean(false),
PH_HOME: mkPath(_PH_HOME),
PH_PROJECT_ROOT: mkPath(_PH_PROJECT_ROOT),
PH_BUILD_ROOT: mkPath(_PH_BUILD_ROOT, { required: false }),
@ -158,6 +160,8 @@ export const instanceLogger = () => ioc.service('instanceLogger')
/**
* Accessors
*/
export const UPGRADE_MODE = () => settings().UPGRADE_MODE
export const PH_HOME = () => settings().PH_HOME
export const PH_PROJECT_ROOT = () => settings().PH_PROJECT_ROOT
export const PH_BUILD_ROOT = () => settings().PH_BUILD_ROOT

View File

@ -4,6 +4,7 @@ import {
INSTANCE_APP_HOOK_DIR,
INSTANCE_APP_MIGRATIONS_DIR,
INSTANCE_DATA_DB,
UPGRADE_MODE,
mkAppUrl,
mkContainerHomePath,
mkDocUrl,
@ -305,13 +306,19 @@ export const instanceService = mkSingleton(
return cp
} catch (e) {
warn(`Error spawning: ${e}`)
await updateInstance(instance.id, {
maintenance: true,
})
userInstanceLogger.error(
`Could not launch container. Instance has been placed in maintenace mode. Please review your instance logs at https://app.pockethost.io/app/instances/${instance.id} or contact support at https://pockethost.io/support`,
)
throw new Error(`Maintenance mode`)
if (UPGRADE_MODE()) {
throw new Error(
`PocketHost is rebooting. Try again in a few seconds.`,
)
} else {
await updateInstance(instance.id, {
maintenance: true,
})
userInstanceLogger.error(
`Could not launch container. Instance has been placed in maintenace mode. Please review your instance logs at https://app.pockethost.io/app/instances/${instance.id} or contact support at https://pockethost.io/support`,
)
throw new Error(`Maintenance mode`)
}
}
})()
const { pid: _pid, exitCode } = childProcess