From 7bb98ba95f95aaf53eccfe7cf5c0776eedb75736 Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Mon, 11 Dec 2023 11:30:18 -0500 Subject: [PATCH] fix(striker-ui-api): add force option to shutdown server --- .../lib/request_handlers/command/buildPowerHandler.ts | 11 ++++++++--- .../src/types/BuildPowerHandlerFunction.d.ts | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/striker-ui-api/src/lib/request_handlers/command/buildPowerHandler.ts b/striker-ui-api/src/lib/request_handlers/command/buildPowerHandler.ts index 47ba5015..d1f6d1ba 100644 --- a/striker-ui-api/src/lib/request_handlers/command/buildPowerHandler.ts +++ b/striker-ui-api/src/lib/request_handlers/command/buildPowerHandler.ts @@ -49,8 +49,10 @@ const MAP_TO_POWER_JOB_PARAMS_BUILDER: Record< job_name: 'set_power::off', job_title: 'job_0332', }), - stopserver: ({ uuid } = {}) => ({ - job_command: `${SERVER_PATHS.usr.sbin['anvil-shutdown-server'].self} --server-uuid '${uuid}'`, + stopserver: ({ force, uuid } = {}) => ({ + job_command: `${ + SERVER_PATHS.usr.sbin['anvil-shutdown-server'].self + } --server-uuid '${uuid}'${force ? ' --immediate' : ''}`, job_description: 'job_0343', job_name: 'set_power::server::off', job_title: 'job_0342', @@ -76,8 +78,11 @@ export const buildPowerHandler: ( (task) => async (request, response) => { const { params: { uuid }, + query: { force: rForce }, } = request; + const force = sanitize(rForce, 'boolean'); + try { if (uuid) { assert( @@ -92,7 +97,7 @@ export const buildPowerHandler: ( } try { - await queuePowerJob(task, { uuid }); + await queuePowerJob(task, { force, uuid }); } catch (error) { stderr(`Failed to ${task} ${uuid ?? LOCAL}; CAUSE: ${error}`); diff --git a/striker-ui-api/src/types/BuildPowerHandlerFunction.d.ts b/striker-ui-api/src/types/BuildPowerHandlerFunction.d.ts index fbdd0e67..e22a309c 100644 --- a/striker-ui-api/src/types/BuildPowerHandlerFunction.d.ts +++ b/striker-ui-api/src/types/BuildPowerHandlerFunction.d.ts @@ -9,6 +9,7 @@ type PowerTask = type PowerJobParams = Omit; type BuildPowerJobParamsOptions = { + force?: boolean; isStopServers?: boolean; uuid?: string; };