Compare commits

...
Author SHA1 Message Date
93094049+kraemr@users.noreply.github.com 367c48238a added restart with backend debug 2025-09-08 12:25:07 +02:00
6 changed files with 71 additions and 2 deletions

No files matched your search

@@ -1,5 +1,7 @@
export const TROUBLESHOOT_REBOOT_HMI = "troubleshoot:reboot-hmi";
export const TROUBLESHOOT_RESTART_BACKEND = "troubleshoot:restart-backend";
export const TROUBLESHOOT_RESTART_BACKEND_DEBUG =
"troubleshoot:restart-backend-debug";
export const TROUBLESHOOT_START_LOG_STREAM = "troubleshoot:start-log-stream";
export const TROUBLESHOOT_STOP_LOG_STREAM = "troubleshoot:stop-log-stream";
export const TROUBLESHOOT_LOG_DATA = "troubleshoot:log-data";
@@ -4,6 +4,7 @@ import {
TROUBLESHOOT_START_LOG_STREAM,
TROUBLESHOOT_STOP_LOG_STREAM,
TROUBLESHOOT_LOG_DATA,
TROUBLESHOOT_RESTART_BACKEND_DEBUG,
} from "./troubleshoot-channels";
export function exposeTroubleshootContext() {
@@ -11,6 +12,8 @@ export function exposeTroubleshootContext() {
contextBridge.exposeInMainWorld("troubleshoot", {
rebootHmi: () => ipcRenderer.invoke(TROUBLESHOOT_REBOOT_HMI),
restartBackend: () => ipcRenderer.invoke(TROUBLESHOOT_RESTART_BACKEND),
restartBackendDebug: () =>
ipcRenderer.invoke(TROUBLESHOOT_RESTART_BACKEND_DEBUG),
startLogStream: () => ipcRenderer.invoke(TROUBLESHOOT_START_LOG_STREAM),
stopLogStream: () => ipcRenderer.invoke(TROUBLESHOOT_STOP_LOG_STREAM),
onLogData: (callback: (log: string) => void) =>
@@ -6,8 +6,9 @@ import {
TROUBLESHOOT_START_LOG_STREAM,
TROUBLESHOOT_STOP_LOG_STREAM,
TROUBLESHOOT_LOG_DATA,
TROUBLESHOOT_RESTART_BACKEND_DEBUG,
} from "./troubleshoot-channels";
import { exec } from "child_process";
let logStreamProcess: ChildProcess | null = null;
export function addTroubleshootEventListeners() {
@@ -24,6 +25,24 @@ export function addTroubleshootEventListeners() {
}
});
ipcMain.handle(TROUBLESHOOT_RESTART_BACKEND_DEBUG, async () => {
return new Promise<{ success: boolean; error?: string }>((resolve) => {
exec(
`sudo systemctl set-environment RUST_LOG=debug && sudo systemctl restart qitech-control-server`,
(error, stdout, stderr) => {
if (error) {
resolve({
success: false,
error: stderr || error.message,
});
} else {
resolve({ success: true });
}
},
);
});
});
ipcMain.handle(TROUBLESHOOT_RESTART_BACKEND, async () => {
try {
const process = spawn(
@@ -25,6 +25,20 @@ export async function rebootHmi(): Promise<{
}
}
export async function restartBackendDebug(): Promise<{
success: boolean;
error?: string;
}> {
try {
return await window.troubleshoot.restartBackendDebug();
} catch (error) {
return {
success: false,
error: error instanceof Error ? error.message : String(error),
};
}
}
export async function restartBackend(): Promise<{
success: boolean;
error?: string;
+31 -1
View File
@@ -4,7 +4,11 @@ import { SectionTitle } from "@/components/SectionTitle";
import { Terminal } from "@/components/Terminal";
import { TouchButton } from "@/components/touch/TouchButton";
import { useLogsStore } from "@/stores/logsStore";
import { rebootHmi, restartBackend } from "@/helpers/troubleshoot_helpers";
import {
rebootHmi,
restartBackend,
restartBackendDebug,
} from "@/helpers/troubleshoot_helpers";
import React, { useState } from "react";
import { toast } from "sonner";
@@ -50,6 +54,22 @@ export function TroubleshootPage() {
}
};
const handleRestartBackendDebug = async () => {
setIsRestartLoading(true);
try {
const result = await restartBackendDebug();
if (result.success) {
toast.success("Backend service restart initiated");
} else {
toast.error(`Failed to restart backend: ${result.error}`);
}
} catch (error) {
toast.error(`Failed to restart backend: ${error}`);
} finally {
setIsRestartLoading(false);
}
};
return (
<Page>
<SectionTitle title="System Troubleshoot" />
@@ -74,6 +94,16 @@ export function TroubleshootPage() {
>
Restart Backend Process
</TouchButton>
<TouchButton
variant="outline"
icon="lu:RotateCcw"
isLoading={isRestartLoading}
onClick={handleRestartBackendDebug}
className="w-max"
>
Restart Backend With Debug Logging
</TouchButton>
</div>
<Alert title="Troubleshoot Actions Info" variant="warning">
+1
View File
@@ -51,6 +51,7 @@ interface UpdateContext {
interface TroubleshootContext {
rebootHmi: () => Promise<{ success: boolean; error?: string }>;
restartBackend: () => Promise<{ success: boolean; error?: string }>;
restartBackendDebug: () => Promise<{ success: boolean; error?: string }>;
startLogStream: () => Promise<{ success: boolean; error?: string }>;
stopLogStream: () => Promise<{ success: boolean; error?: string }>;
onLogData: (callback: (log: string) => void) => void;