mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-07-08 23:45:22 +02:00
feat: add kill process functionality to deployments
- Implemented a new mutation to kill a running deployment process by its PID. - Updated the deployment schema to include a PID field. - Enhanced the deployment service to handle process termination and status updates. - Modified the deployment scripts to echo PID and schedule ID for better tracking. - Added error handling for the kill process operation.
This commit is contained in:
@@ -7,16 +7,21 @@ import {
|
||||
deployments,
|
||||
} from "@/server/db/schema";
|
||||
import {
|
||||
execAsync,
|
||||
execAsyncRemote,
|
||||
findAllDeploymentsByApplicationId,
|
||||
findAllDeploymentsByComposeId,
|
||||
findAllDeploymentsByServerId,
|
||||
findApplicationById,
|
||||
findComposeById,
|
||||
findDeploymentById,
|
||||
findServerById,
|
||||
updateDeploymentStatus,
|
||||
} from "@dokploy/server";
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { desc, eq } from "drizzle-orm";
|
||||
import { createTRPCRouter, protectedProcedure } from "../trpc";
|
||||
import { z } from "zod";
|
||||
|
||||
export const deploymentRouter = createTRPCRouter({
|
||||
all: protectedProcedure
|
||||
@@ -72,4 +77,30 @@ export const deploymentRouter = createTRPCRouter({
|
||||
|
||||
return deploymentsList;
|
||||
}),
|
||||
|
||||
killProcess: protectedProcedure
|
||||
.input(
|
||||
z.object({
|
||||
deploymentId: z.string().min(1),
|
||||
}),
|
||||
)
|
||||
.mutation(async ({ input }) => {
|
||||
const deployment = await findDeploymentById(input.deploymentId);
|
||||
|
||||
if (!deployment.pid) {
|
||||
throw new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
message: "Deployment is not running",
|
||||
});
|
||||
}
|
||||
|
||||
const command = `kill -9 ${deployment.pid}`;
|
||||
if (deployment.schedule?.serverId) {
|
||||
await execAsyncRemote(deployment.schedule.serverId, command);
|
||||
} else {
|
||||
await execAsync(command);
|
||||
}
|
||||
|
||||
await updateDeploymentStatus(deployment.deploymentId, "error");
|
||||
}),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user