Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions backend/agent-socket-handlers/docker-socket-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,49 @@ export class DockerSocketHandler extends AgentSocketHandler {
}
});

agentSocket.on("pauseStack", async (stackName : unknown, callback) => {
try {
checkLogin(socket);

if (typeof(stackName) !== "string") {
throw new ValidationError("Stack name must be a string");
}

const stack = await Stack.getStack(server, stackName);
await stack.pause(socket);
callbackResult({
ok: true,
msg: "Paused",
msgi18n: true,
}, callback);
server.sendStackList();
} catch (e) {
callbackError(e, callback);
}
});

// unpauseStack
agentSocket.on("unpauseStack", async (stackName : unknown, callback) => {
try {
checkLogin(socket);

if (typeof(stackName) !== "string") {
throw new ValidationError("Stack name must be a string");
}

const stack = await Stack.getStack(server, stackName);
await stack.unpause(socket);
callbackResult({
ok: true,
msg: "Unpaused",
msgi18n: true,
}, callback);
server.sendStackList();
} catch (e) {
callbackError(e, callback);
}
});

// Services status
agentSocket.on("serviceStatusList", async (stackName : unknown, callback) => {
try {
Expand Down
22 changes: 22 additions & 0 deletions backend/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
CREATED_STACK,
EXITED, getCombinedTerminalName,
getComposeTerminalName, getContainerExecTerminalName,
PAUSED,
PROGRESS_TERMINAL_ROWS,
RUNNING, TERMINAL_ROWS,
UNKNOWN
Expand Down Expand Up @@ -363,6 +364,9 @@ export class Stack {
static statusConvert(status : string) : number {
if (status.startsWith("created")) {
return CREATED_STACK;
} else if (status.includes("paused")) {
// If one of the services is paused, we consider the stack is paused
return PAUSED;
} else if (status.includes("exited")) {
// If one of the service is exited, we consider the stack is exited
return EXITED;
Expand Down Expand Up @@ -456,6 +460,24 @@ export class Stack {
return exitCode;
}

async pause(socket: DockgeSocket) : Promise<number> {
const terminalName = getComposeTerminalName(socket.endpoint, this.name);
let exitCode = await Terminal.exec(this.server, socket, terminalName, "docker", this.getComposeOptions("pause"), this.path);
if (exitCode !== 0) {
throw new Error("Failed to pause, please check the terminal output for more information.");
}
return exitCode;
}

async unpause(socket: DockgeSocket) : Promise<number> {
const terminalName = getComposeTerminalName(socket.endpoint, this.name);
let exitCode = await Terminal.exec(this.server, socket, terminalName, "docker", this.getComposeOptions("unpause"), this.path);
if (exitCode !== 0) {
throw new Error("Failed to unpause, please check the terminal output for more information.");
}
return exitCode;
}

async update(socket: DockgeSocket) {
const terminalName = getComposeTerminalName(socket.endpoint, this.name);
let exitCode = await Terminal.exec(this.server, socket, terminalName, "docker", this.getComposeOptions("pull"), this.path);
Expand Down
7 changes: 7 additions & 0 deletions common/util-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const CREATED_FILE = 1;
export const CREATED_STACK = 2;
export const RUNNING = 3;
export const EXITED = 4;
export const PAUSED = 5;

export function statusName(status : number) : string {
switch (status) {
Expand All @@ -62,6 +63,8 @@ export function statusName(status : number) : string {
return "running";
case EXITED:
return "exited";
case PAUSED:
return "paused";
default:
return "unknown";
}
Expand All @@ -77,6 +80,8 @@ export function statusNameShort(status : number) : string {
return "active";
case EXITED:
return "exited";
case PAUSED:
return "paused";
default:
return "?";
}
Expand All @@ -92,6 +97,8 @@ export function statusColor(status : number) : string {
return "primary";
case EXITED:
return "danger";
case PAUSED:
return "warning";
default:
return "secondary";
}
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
"restartStack": "Restart",
"updateStack": "Update",
"startStack": "Start",
"pauseStack": "Pause",
"unpauseStack": "Unpause",
"downStack": "Stop & Inactive",
"editStack": "Edit",
"discardStack": "Discard",
Expand Down Expand Up @@ -86,6 +88,7 @@
"active": "active",
"exited": "exited",
"inactive": "inactive",
"paused": "paused",
"Appearance": "Appearance",
"Security": "Security",
"About": "About",
Expand Down Expand Up @@ -123,6 +126,8 @@
"Started": "Started",
"Stopped": "Stopped",
"Restarted": "Restarted",
"Paused": "Paused",
"Unpaused": "Unpaused",
"Downed": "Downed",
"Switch to sh": "Switch to sh",
"terminal": "Terminal",
Expand Down
33 changes: 32 additions & 1 deletion frontend/src/pages/Compose.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@
{{ $t("editStack") }}
</button>

<button v-if="!isEditMode && !active" class="btn btn-primary" :disabled="processing" @click="startStack">
<button v-if="!isEditMode && !active && !paused" class="btn btn-primary" :disabled="processing" @click="startStack">
<font-awesome-icon icon="play" class="me-1" />
{{ $t("startStack") }}
</button>

<button v-if="!isEditMode && paused" class="btn btn-primary" :disabled="processing" @click="unpauseStack">
<font-awesome-icon icon="play" class="me-1" />
{{ $t("unpauseStack") }}
</button>
<button v-if="!isEditMode && active" class="btn btn-normal " :disabled="processing" @click="restartStack">
<font-awesome-icon icon="rotate" class="me-1" />
{{ $t("restartStack") }}
Expand All @@ -51,6 +55,10 @@
<font-awesome-icon icon="stop" class="me-1" />
{{ $t("downStack") }}
</BDropdownItem>
<BDropdownItem v-if="active" @click="pauseStack">
<font-awesome-icon icon="pause" class="me-1" />
{{ $t("pauseStack") }}
</BDropdownItem>
</BDropdown>
</div>

Expand Down Expand Up @@ -257,6 +265,7 @@ import {
copyYAMLComments, envsubstYAML,
getCombinedTerminalName,
getComposeTerminalName,
PAUSED,
PROGRESS_TERMINAL_ROWS,
RUNNING
} from "../../../common/util-common";
Expand Down Expand Up @@ -391,6 +400,10 @@ export default {
active() {
return this.status === RUNNING;
},

paused() {
return this.status === PAUSED;
},

terminalName() {
if (!this.stack.name) {
Expand Down Expand Up @@ -685,6 +698,24 @@ export default {
});
},

pauseStack() {
this.processing = true;

this.$root.emitAgent(this.endpoint, "pauseStack", this.stack.name, (res) => {
this.processing = false;
this.$root.toastRes(res);
});
},

unpauseStack() {
this.processing = true;

this.$root.emitAgent(this.endpoint, "unpauseStack", this.stack.name, (res) => {
this.processing = false;
this.$root.toastRes(res);
});
},

discardStack() {
this.loadStack();
this.isEditMode = false;
Expand Down
Loading