fix(striker-ui-api): add force option to shutdown server

main
Tsu-ba-me 1 year ago
parent 20ae35758a
commit 7bb98ba95f
  1. 11
      striker-ui-api/src/lib/request_handlers/command/buildPowerHandler.ts
  2. 1
      striker-ui-api/src/types/BuildPowerHandlerFunction.d.ts

@ -49,8 +49,10 @@ const MAP_TO_POWER_JOB_PARAMS_BUILDER: Record<
job_name: 'set_power::off', job_name: 'set_power::off',
job_title: 'job_0332', job_title: 'job_0332',
}), }),
stopserver: ({ uuid } = {}) => ({ stopserver: ({ force, uuid } = {}) => ({
job_command: `${SERVER_PATHS.usr.sbin['anvil-shutdown-server'].self} --server-uuid '${uuid}'`, job_command: `${
SERVER_PATHS.usr.sbin['anvil-shutdown-server'].self
} --server-uuid '${uuid}'${force ? ' --immediate' : ''}`,
job_description: 'job_0343', job_description: 'job_0343',
job_name: 'set_power::server::off', job_name: 'set_power::server::off',
job_title: 'job_0342', job_title: 'job_0342',
@ -76,8 +78,11 @@ export const buildPowerHandler: (
(task) => async (request, response) => { (task) => async (request, response) => {
const { const {
params: { uuid }, params: { uuid },
query: { force: rForce },
} = request; } = request;
const force = sanitize(rForce, 'boolean');
try { try {
if (uuid) { if (uuid) {
assert( assert(
@ -92,7 +97,7 @@ export const buildPowerHandler: (
} }
try { try {
await queuePowerJob(task, { uuid }); await queuePowerJob(task, { force, uuid });
} catch (error) { } catch (error) {
stderr(`Failed to ${task} ${uuid ?? LOCAL}; CAUSE: ${error}`); stderr(`Failed to ${task} ${uuid ?? LOCAL}; CAUSE: ${error}`);

@ -9,6 +9,7 @@ type PowerTask =
type PowerJobParams = Omit<JobParams, 'file' | 'line'>; type PowerJobParams = Omit<JobParams, 'file' | 'line'>;
type BuildPowerJobParamsOptions = { type BuildPowerJobParamsOptions = {
force?: boolean;
isStopServers?: boolean; isStopServers?: boolean;
uuid?: string; uuid?: string;
}; };

Loading…
Cancel
Save