diff --git a/docs/content/docs/en/operations/multi-node.mdx b/docs/content/docs/en/operations/multi-node.mdx index abcffac62..1916d884a 100644 --- a/docs/content/docs/en/operations/multi-node.mdx +++ b/docs/content/docs/en/operations/multi-node.mdx @@ -39,6 +39,24 @@ and emitting `node.up` / `node.down` events (see the those as read-only **transitive** sub-nodes (Node 1 → Node 2 → Node 3). +### Restart a node + +Open a directly configured node's action menu and choose **Restart Xray** or +**Restart Panel**, then confirm the node name. Restart Xray interrupts that +node's active Xray connections. Restart Panel restarts its panel and subscription +services after a three-second delay; the success message acknowledges the request, +and the node may be temporarily unavailable. + +Restart actions are disabled for disabled nodes and read-only transitive nodes. +An enabled node can be contacted even when its last heartbeat says offline. +Connection and permission failures are reported without automatically retrying. + +Xray restart supports the node's existing `node-sync`, `node-admin`, and `admin` +API tokens. Panel restart requires `node-admin` or `admin`; mTLS connections must +also present an explicit `node-admin` bearer token. Update older nodes before +using `node-admin` for panel restart. The master-side node actions retain the +normal Nodes API permissions. + ### Mutual TLS (mTLS) between master and node For the strongest trust, use `tlsVerifyMode = mtls` (requires `https`): diff --git a/docs/content/docs/en/reference/api/nodes.mdx b/docs/content/docs/en/reference/api/nodes.mdx index c81d856e9..fb6e627e3 100644 --- a/docs/content/docs/en/reference/api/nodes.mdx +++ b/docs/content/docs/en/reference/api/nodes.mdx @@ -69,6 +69,20 @@ _openapi: - depth: 2 title: Probe an existing node, updating its cached health state. url: '#probe-an-existing-node-updating-its-cached-health-state' + - depth: 2 + title: Restart Xray on one enabled, directly configured node. Active Xray + connections are interrupted. Uses the node runtime and accepts admin, + node-admin or node-sync credentials on the node. A stale heartbeat does + not prevent the request. + url: '#restart-xray-on-one-enabled-directly-configured-node-active-xray-connections-are-interrupted-uses-the-node-runtime-and-accepts-admin-node-admin-or-node-sync-credentials-on-the-node-a-stale-heartbeat-does-not-prevent-the-request' + - depth: 2 + title: Request a restart of the panel and subscription services on one enabled, + directly configured node. Requires admin or node-admin credentials on + the node; mTLS requires an explicit node-admin bearer token. Success + acknowledges scheduling, before the three-second restart delay. A stale + heartbeat does not prevent the request. Older nodes may reject + node-admin access until upgraded. + url: '#request-a-restart-of-the-panel-and-subscription-services-on-one-enabled-directly-configured-node-requires-admin-or-node-admin-credentials-on-the-node-mtls-requires-an-explicit-node-admin-bearer-token-success-acknowledges-scheduling-before-the-three-second-restart-delay-a-stale-heartbeat-does-not-prevent-the-request-older-nodes-may-reject-node-admin-access-until-upgraded' - depth: 2 title: 'Trigger the official panel self-updater on each given node (downloads the latest release and restarts). Only enabled, online nodes are @@ -130,6 +144,18 @@ _openapi: id: use-unsaved-node-connection-details-to-list-the-remote-inbounds-available-for-selective-import - content: Probe an existing node, updating its cached health state. id: probe-an-existing-node-updating-its-cached-health-state + - content: Restart Xray on one enabled, directly configured node. Active Xray + connections are interrupted. Uses the node runtime and accepts admin, + node-admin or node-sync credentials on the node. A stale heartbeat + does not prevent the request. + id: restart-xray-on-one-enabled-directly-configured-node-active-xray-connections-are-interrupted-uses-the-node-runtime-and-accepts-admin-node-admin-or-node-sync-credentials-on-the-node-a-stale-heartbeat-does-not-prevent-the-request + - content: Request a restart of the panel and subscription services on one + enabled, directly configured node. Requires admin or node-admin + credentials on the node; mTLS requires an explicit node-admin bearer + token. Success acknowledges scheduling, before the three-second + restart delay. A stale heartbeat does not prevent the request. Older + nodes may reject node-admin access until upgraded. + id: request-a-restart-of-the-panel-and-subscription-services-on-one-enabled-directly-configured-node-requires-admin-or-node-admin-credentials-on-the-node-mtls-requires-an-explicit-node-admin-bearer-token-success-acknowledges-scheduling-before-the-three-second-restart-delay-a-stale-heartbeat-does-not-prevent-the-request-older-nodes-may-reject-node-admin-access-until-upgraded - content: 'Trigger the official panel self-updater on each given node (downloads the latest release and restarts). Only enabled, online nodes are updated; offline/disabled ones are reported as skipped. Set "dev": @@ -149,7 +175,7 @@ export default function Layout(props) { return ( <> {props.children} - + ); } \ No newline at end of file diff --git a/docs/public/images/node-restart-confirm.png b/docs/public/images/node-restart-confirm.png new file mode 100644 index 000000000..c125a18b1 Binary files /dev/null and b/docs/public/images/node-restart-confirm.png differ diff --git a/docs/public/images/node-restart-desktop.png b/docs/public/images/node-restart-desktop.png new file mode 100644 index 000000000..72e0f1c42 Binary files /dev/null and b/docs/public/images/node-restart-desktop.png differ diff --git a/docs/public/images/node-restart-mobile.png b/docs/public/images/node-restart-mobile.png new file mode 100644 index 000000000..cdc134b1d Binary files /dev/null and b/docs/public/images/node-restart-mobile.png differ diff --git a/docs/public/openapi.json b/docs/public/openapi.json index 8a478f289..797fcd749 100644 --- a/docs/public/openapi.json +++ b/docs/public/openapi.json @@ -12252,6 +12252,88 @@ } } }, + "/panel/api/nodes/restartXray/{id}": { + "post": { + "tags": [ + "Nodes" + ], + "summary": "Restart Xray on one enabled, directly configured node. Active Xray connections are interrupted. Uses the node runtime and accepts admin, node-admin or node-sync credentials on the node. A stale heartbeat does not prevent the request.", + "operationId": "post_panel_api_nodes_restartXray_id", + "parameters": [ + { + "name": "id", + "in": "path", + "required": true, + "description": "Node ID.", + "schema": { + "type": "integer" + } + } + ], + "responses": { + "200": { + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "success": { + "type": "boolean" + }, + "msg": { + "type": "string" + }, + "obj": {} + } + } + } + } + } + } + } + }, + "/panel/api/nodes/restartPanel/{id}": { + "post": { + "tags": [ + "Nodes" + ], + "summary": "Request a restart of the panel and subscription services on one enabled, directly configured node. Requires admin or node-admin credentials on the node; mTLS requires an explicit node-admin bearer token. Success acknowledges scheduling, before the three-second restart delay. A stale heartbeat does not prevent the request. Older nodes may reject node-admin access until upgraded.", + "operationId": "post_panel_api_nodes_restartPanel_id", + "parameters": [ + { + "name": "id", + "in": "path", + "required": true, + "description": "Node ID.", + "schema": { + "type": "integer" + } + } + ], + "responses": { + "200": { + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "success": { + "type": "boolean" + }, + "msg": { + "type": "string" + }, + "obj": {} + } + } + } + } + } + } + } + }, "/panel/api/nodes/updatePanel": { "post": { "tags": [ diff --git a/frontend/public/openapi.json b/frontend/public/openapi.json index 8a478f289..797fcd749 100644 --- a/frontend/public/openapi.json +++ b/frontend/public/openapi.json @@ -12252,6 +12252,88 @@ } } }, + "/panel/api/nodes/restartXray/{id}": { + "post": { + "tags": [ + "Nodes" + ], + "summary": "Restart Xray on one enabled, directly configured node. Active Xray connections are interrupted. Uses the node runtime and accepts admin, node-admin or node-sync credentials on the node. A stale heartbeat does not prevent the request.", + "operationId": "post_panel_api_nodes_restartXray_id", + "parameters": [ + { + "name": "id", + "in": "path", + "required": true, + "description": "Node ID.", + "schema": { + "type": "integer" + } + } + ], + "responses": { + "200": { + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "success": { + "type": "boolean" + }, + "msg": { + "type": "string" + }, + "obj": {} + } + } + } + } + } + } + } + }, + "/panel/api/nodes/restartPanel/{id}": { + "post": { + "tags": [ + "Nodes" + ], + "summary": "Request a restart of the panel and subscription services on one enabled, directly configured node. Requires admin or node-admin credentials on the node; mTLS requires an explicit node-admin bearer token. Success acknowledges scheduling, before the three-second restart delay. A stale heartbeat does not prevent the request. Older nodes may reject node-admin access until upgraded.", + "operationId": "post_panel_api_nodes_restartPanel_id", + "parameters": [ + { + "name": "id", + "in": "path", + "required": true, + "description": "Node ID.", + "schema": { + "type": "integer" + } + } + ], + "responses": { + "200": { + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "success": { + "type": "boolean" + }, + "msg": { + "type": "string" + }, + "obj": {} + } + } + } + } + } + } + } + }, "/panel/api/nodes/updatePanel": { "post": { "tags": [ diff --git a/frontend/src/api/queries/useNodeMutations.ts b/frontend/src/api/queries/useNodeMutations.ts index af87d178a..c773d4e48 100644 --- a/frontend/src/api/queries/useNodeMutations.ts +++ b/frontend/src/api/queries/useNodeMutations.ts @@ -83,12 +83,29 @@ export function useNodeMutations() { }, }); + const restartMut = useMutation({ + mutationFn: ({ id, target }: { id: number; target: 'xray' | 'panel' }) => + HttpUtil.post( + `/panel/api/nodes/${target === 'xray' ? 'restartXray' : 'restartPanel'}/${id}`, + undefined, + { + silent: true, + timeout: 12000, + }, + ), + retry: false, + onSuccess: (msg) => { + if (msg?.success) queryClient.invalidateQueries({ queryKey: keys.nodes.root() }); + }, + }); + return { create: (payload: Partial) => createMut.mutateAsync(payload), update: (id: number, payload: Partial) => updateMut.mutateAsync({ id, payload }), remove: (id: number) => removeMut.mutateAsync(id), setEnable: (id: number, enable: boolean) => setEnableMut.mutateAsync({ id, enable }), probe: (id: number) => probeMut.mutateAsync(id), + restart: (id: number, target: 'xray' | 'panel') => restartMut.mutateAsync({ id, target }), updatePanels: (ids: number[], dev: boolean): Promise> => updatePanelsMut.mutateAsync({ ids, dev }), testConnection: async (payload: Partial): Promise> => { diff --git a/frontend/src/pages/api-docs/endpoints.ts b/frontend/src/pages/api-docs/endpoints.ts index 8ecb6fa30..6704c4362 100644 --- a/frontend/src/pages/api-docs/endpoints.ts +++ b/frontend/src/pages/api-docs/endpoints.ts @@ -1853,6 +1853,20 @@ export const sections: readonly Section[] = [ summary: 'Probe an existing node, updating its cached health state.', params: [{ name: 'id', in: 'path', type: 'number', desc: 'Node ID.' }], }, + { + method: 'POST', + path: '/panel/api/nodes/restartXray/:id', + summary: + 'Restart Xray on one enabled, directly configured node. Active Xray connections are interrupted. Uses the node runtime and accepts admin, node-admin or node-sync credentials on the node. A stale heartbeat does not prevent the request.', + params: [{ name: 'id', in: 'path', type: 'number', desc: 'Node ID.' }], + }, + { + method: 'POST', + path: '/panel/api/nodes/restartPanel/:id', + summary: + 'Request a restart of the panel and subscription services on one enabled, directly configured node. Requires admin or node-admin credentials on the node; mTLS requires an explicit node-admin bearer token. Success acknowledges scheduling, before the three-second restart delay. A stale heartbeat does not prevent the request. Older nodes may reject node-admin access until upgraded.', + params: [{ name: 'id', in: 'path', type: 'number', desc: 'Node ID.' }], + }, { method: 'POST', path: '/panel/api/nodes/updatePanel', diff --git a/frontend/src/pages/nodes/NodeList.tsx b/frontend/src/pages/nodes/NodeList.tsx index 467dc704c..17185f869 100644 --- a/frontend/src/pages/nodes/NodeList.tsx +++ b/frontend/src/pages/nodes/NodeList.tsx @@ -1,4 +1,4 @@ -import { useMemo, useState } from 'react'; +import { useCallback, useMemo, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Badge, Button, Card, Dropdown, Modal, Space, Switch, Table, Tag, Tooltip } from 'antd'; import type { BadgeProps } from 'antd'; @@ -15,6 +15,7 @@ import { InfoCircleOutlined, MoreOutlined, PlusOutlined, + ReloadOutlined, RightOutlined, SafetyCertificateOutlined, TeamOutlined, @@ -42,8 +43,12 @@ interface NodeListProps { onToggleEnable: (node: NodeRecord, next: boolean) => void; onUpdateNode: (node: NodeRecord) => void; onUpdateSelected: () => void; + onRestart: (node: NodeRecord, target: 'xray' | 'panel') => void; + restartingIds?: ReadonlySet; } +const noRestarts: ReadonlySet = new Set(); + function isUpdateEligible(n: NodeRecord): boolean { return !!n.enable && n.status === 'online'; } @@ -187,6 +192,8 @@ export default function NodeList({ onToggleEnable, onUpdateNode, onUpdateSelected, + onRestart, + restartingIds = noRestarts, }: NodeListProps) { const { t } = useTranslation(); const relativeTime = useRelativeTime(); @@ -195,6 +202,18 @@ export default function NodeList({ const [statsNode, setStatsNode] = useState(null); const [expandedIds, setExpandedIds] = useState>(new Set()); + const restartItems = useCallback( + (node: NodeRecord) => + (['xray', 'panel'] as const).map((target) => ({ + key: `restart-${target}`, + icon: , + label: t(`pages.nodes.${target === 'xray' ? 'restartXray' : 'restartPanel'}`), + disabled: !node.enable || !!node.transitive || restartingIds.has(node.id), + onClick: () => onRestart(node, target), + })), + [t, onRestart, restartingIds], + ); + // Map a direct node's GUID to its display name so a transitive sub-node can show // which parent it is reached through (#4983); the master walks one level only. const nameByGuid = useMemo(() => { @@ -299,6 +318,14 @@ export default function NodeList({ onClick={() => onEdit(record)} /> + +