Skip to content

Commit 032e4f2

Browse files
authored
Apply node maintenance mode to servers (pterodactyl#4421)
1 parent 4032481 commit 032e4f2

File tree

11 files changed

+29
-5
lines changed

11 files changed

+29
-5
lines changed

app/Exceptions/Http/Server/ServerStateConflictException.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public function __construct(Server $server, Throwable $previous = null)
1717
$message = 'This server is currently in an unsupported state, please try again later.';
1818
if ($server->isSuspended()) {
1919
$message = 'This server is currently suspended and the functionality requested is unavailable.';
20+
} elseif ($server->node->isUnderMaintenance()) {
21+
$message = 'The node of this server is currently under maintenance and the functionality requested is unavailable.';
2022
} elseif (!$server->isInstalled()) {
2123
$message = 'This server has not yet completed its installation process, please try again later.';
2224
} elseif ($server->status === Server::STATUS_RESTORING_BACKUP) {

app/Http/Middleware/Api/Client/Server/AuthenticateServerAccess.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function handle(Request $request, Closure $next): mixed
5353
// Still allow users to get information about their server if it is installing or
5454
// being transferred.
5555
if (!$request->routeIs('api:client:server.view')) {
56-
if ($server->isSuspended() && !$request->routeIs('api:client:server.resources')) {
56+
if (($server->isSuspended() || $server->node->isUnderMaintenance()) && !$request->routeIs('api:client:server.resources')) {
5757
throw $exception;
5858
}
5959
if (!$user->root_admin || !$request->routeIs($this->except)) {

app/Http/Requests/Api/Application/Nodes/StoreNodeRequest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public function rules(array $rules = null): array
2424
'fqdn',
2525
'scheme',
2626
'behind_proxy',
27+
'maintenance_mode',
2728
'memory',
2829
'memory_overallocate',
2930
'disk',

app/Models/Node.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@ public function getDecryptedKey(): string
186186
);
187187
}
188188

189+
public function isUnderMaintenance(): bool
190+
{
191+
return $this->maintenance_mode;
192+
}
193+
189194
public function mounts(): HasManyThrough
190195
{
191196
return $this->hasManyThrough(Mount::class, MountNode::class, 'node_id', 'id', 'id', 'mount_id');

app/Models/Server.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ public function validateCurrentState()
354354
{
355355
if (
356356
$this->isSuspended() ||
357+
$this->node->isUnderMaintenance() ||
357358
!$this->isInstalled() ||
358359
$this->status === self::STATUS_RESTORING_BACKUP ||
359360
!is_null($this->transfer)

app/Transformers/Api/Client/ServerTransformer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public function transform(Server $server): array
4343
'uuid' => $server->uuid,
4444
'name' => $server->name,
4545
'node' => $server->node->name,
46+
'is_node_under_maintenance' => $server->node->isUnderMaintenance(),
4647
'sftp_details' => [
4748
'ip' => $server->node->fqdn,
4849
'port' => $server->node->daemonSFTP,

resources/scripts/api/server/getServer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface Server {
1717
uuid: string;
1818
name: string;
1919
node: string;
20+
isNodeUnderMaintenance: boolean;
2021
status: ServerStatus;
2122
sftpDetails: {
2223
ip: string;
@@ -50,6 +51,7 @@ export const rawDataToServerObject = ({ attributes: data }: FractalResponseData)
5051
uuid: data.uuid,
5152
name: data.name,
5253
node: data.node,
54+
isNodeUnderMaintenance: data.is_node_under_maintenance,
5355
status: data.status,
5456
invocation: data.invocation,
5557
dockerImage: data.docker_image,

resources/scripts/components/server/ConflictStateRenderer.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import ServerRestoreSvg from '@/assets/images/server_restore.svg';
88
export default () => {
99
const status = ServerContext.useStoreState((state) => state.server.data?.status || null);
1010
const isTransferring = ServerContext.useStoreState((state) => state.server.data?.isTransferring || false);
11+
const isNodeUnderMaintenance = ServerContext.useStoreState(
12+
(state) => state.server.data?.isNodeUnderMaintenance || false
13+
);
1114

1215
return status === 'installing' || status === 'install_failed' ? (
1316
<ScreenBlock
@@ -21,6 +24,12 @@ export default () => {
2124
image={ServerErrorSvg}
2225
message={'This server is suspended and cannot be accessed.'}
2326
/>
27+
) : isNodeUnderMaintenance ? (
28+
<ScreenBlock
29+
title={'Node under Maintenance'}
30+
image={ServerErrorSvg}
31+
message={'The node of this server is currently under maintenance.'}
32+
/>
2433
) : (
2534
<ScreenBlock
2635
title={isTransferring ? 'Transferring' : 'Restoring from Backup'}

resources/scripts/components/server/console/ServerConsoleContainer.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@ const ServerConsoleContainer = () => {
1919
const isInstalling = ServerContext.useStoreState((state) => state.server.isInstalling);
2020
const isTransferring = ServerContext.useStoreState((state) => state.server.data!.isTransferring);
2121
const eggFeatures = ServerContext.useStoreState((state) => state.server.data!.eggFeatures, isEqual);
22+
const isNodeUnderMaintenance = ServerContext.useStoreState((state) => state.server.data!.isNodeUnderMaintenance);
2223

2324
return (
2425
<ServerContentBlock title={'Console'}>
25-
{(isInstalling || isTransferring) && (
26+
{(isNodeUnderMaintenance || isInstalling || isTransferring) && (
2627
<Alert type={'warning'} className={'mb-4'}>
27-
{isInstalling
28+
{isNodeUnderMaintenance
29+
? 'The node of this server is currently under maintenance and all actions are unavailable.'
30+
: isInstalling
2831
? 'This server is currently running its installation process and most actions are unavailable.'
2932
: 'This server is currently being transferred to another node and all actions are unavailable.'}
3033
</Alert>

resources/scripts/state/server/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const server: ServerDataStore = {
3030
return false;
3131
}
3232

33-
return state.data.status !== null || state.data.isTransferring;
33+
return state.data.status !== null || state.data.isTransferring || state.data.isNodeUnderMaintenance;
3434
}),
3535

3636
isInstalling: computed((state) => {

0 commit comments

Comments
 (0)