feat(server service): added in start stop and restart from vms036
This commit is contained in:
@@ -2,7 +2,6 @@ import { spawn } from "child_process";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||
import { db } from "../../../../../database/dbclient.js";
|
||||
import { settings } from "../../../../../database/schema/settings.js";
|
||||
import { createLog } from "../../../logger/logger.js";
|
||||
import { serverData } from "../../../../../database/schema/serverData.js";
|
||||
import os from "os";
|
||||
@@ -33,6 +32,12 @@ export const serviceControl = async (
|
||||
scriptPath = `${process.env.DEVFOLDER}\\dist\\server\\scripts\\services.ps1`;
|
||||
}
|
||||
|
||||
console.log(serverInfo[0].serverDNS);
|
||||
const username = process.env.ADMUSER as string;
|
||||
const password = process.env.ADMPASSWORD as string;
|
||||
|
||||
console.log(username, password);
|
||||
|
||||
const args = [
|
||||
"-NoProfile",
|
||||
"-ExecutionPolicy",
|
||||
@@ -47,6 +52,12 @@ export const serviceControl = async (
|
||||
serverInfo[0].serverLoc as string,
|
||||
"-remote",
|
||||
remote ?? "",
|
||||
"-server",
|
||||
serverInfo[0].serverDNS as string,
|
||||
"-username",
|
||||
username,
|
||||
"-admpass",
|
||||
password,
|
||||
];
|
||||
const scriptProcess = spawn("powershell", args);
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||
import hasCorrectRole from "../../../auth/middleware/roleCheck.js";
|
||||
import { serviceControl } from "../../controller/server/serviceControl.js";
|
||||
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||
import { simpleRateLimit } from "../../../../globalUtils/rateLimiter.js";
|
||||
|
||||
// Define the request body schema
|
||||
const requestSchema = z.object({
|
||||
@@ -21,7 +22,11 @@ app.openapi(
|
||||
summary: "Starts, Stops, Restarts the server.",
|
||||
method: "post",
|
||||
path: "/serviceprocess",
|
||||
middleware: [authMiddleware, hasCorrectRole(["systemAdmin"], "admin")],
|
||||
middleware: [
|
||||
authMiddleware,
|
||||
hasCorrectRole(["systemAdmin"], "admin"),
|
||||
simpleRateLimit,
|
||||
],
|
||||
|
||||
request: {
|
||||
body: {
|
||||
@@ -34,7 +39,7 @@ app.openapi(
|
||||
}),
|
||||
async (c) => {
|
||||
const { data, error } = await tryCatch(c.req.json());
|
||||
//apiHit(c, { endpoint: `/serviceprocess`, lastBody: data });
|
||||
//apiHit(c, { endpoint: "/bookin", lastBody: data });
|
||||
if (error) {
|
||||
return c.json({
|
||||
success: false,
|
||||
|
||||
Reference in New Issue
Block a user