MCPcopy
hub / github.com/Dokploy/dokploy / runCommand

Function runCommand

packages/server/src/utils/schedules/utils.ts:39–185  ·  view source on GitHub ↗
(scheduleId: string)

Source from the content-addressed store, hash-verified

37};
38
39export const runCommand = async (scheduleId: string) => {
40 const {
41 application,
42 command,
43 shellType,
44 scheduleType,
45 compose,
46 serviceName,
47 appName,
48 serverId,
49 } = await findScheduleById(scheduleId);
50
51 const deployment = await createDeploymentSchedule({
52 scheduleId,
53 title: "Schedule",
54 description: "Schedule",
55 });
56
57 if (scheduleType === "application" || scheduleType === "compose") {
58 let containerId = "";
59 let serverId = "";
60 if (scheduleType === "application" && application) {
61 const container = await getServiceContainer(
62 application.appName,
63 application.serverId,
64 );
65 containerId = container?.Id || "";
66 serverId = application.serverId || "";
67 }
68 if (scheduleType === "compose" && compose) {
69 const container = await getComposeContainer(compose, serviceName || "");
70 containerId = container?.Id || "";
71 serverId = compose.serverId || "";
72 }
73
74 if (serverId) {
75 try {
76 await execAsyncRemote(
77 serverId,
78 `
79 set -e
80 echo "Running command: docker exec ${containerId} ${shellType} -c '${command}'" >> ${deployment.logPath};
81 docker exec ${containerId} ${shellType} -c '${command}' >> ${deployment.logPath} 2>> ${deployment.logPath} || {
82 echo "❌ Command failed" >> ${deployment.logPath};
83 exit 1;
84 }
85 echo "✅ Command executed successfully" >> ${deployment.logPath};
86 `,
87 );
88 } catch (error) {
89 await updateDeploymentStatus(deployment.deploymentId, "error");
90 throw error;
91 }
92 } else {
93 const writeStream = createWriteStream(deployment.logPath, { flags: "a" });
94
95 try {
96 if (IS_CLOUD) {

Callers 3

runJobsFunction · 0.90
scheduleJobFunction · 0.85
schedule.tsFile · 0.85

Calls 9

findScheduleByIdFunction · 0.90
createDeploymentScheduleFunction · 0.90
getServiceContainerFunction · 0.90
getComposeContainerFunction · 0.90
execAsyncRemoteFunction · 0.90
updateDeploymentStatusFunction · 0.90
spawnAsyncFunction · 0.90
pathsFunction · 0.90
updateDeploymentFunction · 0.90

Tested by

no test coverage detected