mirror of
https://github.com/louislam/dockge.git
synced 2025-02-22 19:45:56 +00:00
add container buttons
Added start and stop service buttons for each service in a stack by changes to the container and compose components as well as the socket handler and the stack class.
This commit is contained in:
parent
109222f024
commit
cc12f7221e
4 changed files with 114 additions and 0 deletions
|
@ -141,6 +141,8 @@ export class DockerSocketHandler extends AgentSocketHandler {
|
|||
msg: "Stopped"
|
||||
}, callback);
|
||||
server.sendStackList();
|
||||
|
||||
stack.leaveCombinedTerminal(socket);
|
||||
} catch (e) {
|
||||
callbackError(e, callback);
|
||||
}
|
||||
|
@ -229,6 +231,49 @@ export class DockerSocketHandler extends AgentSocketHandler {
|
|||
}
|
||||
});
|
||||
|
||||
// Start a service
|
||||
agentSocket.on("startService", async (stackName: unknown, serviceName: unknown, callback) => {
|
||||
try {
|
||||
checkLogin(socket);
|
||||
|
||||
if (typeof (stackName) !== "string" || typeof (serviceName) !== "string") {
|
||||
throw new ValidationError("Stack name and service name must be strings");
|
||||
}
|
||||
|
||||
const stack = await Stack.getStack(server, stackName);
|
||||
await stack.startService(socket, serviceName);
|
||||
stack.joinCombinedTerminal(socket); // Ensure the combined terminal is joined
|
||||
callbackResult({
|
||||
ok: true,
|
||||
msg: `Service ${serviceName} started`
|
||||
}, callback);
|
||||
server.sendStackList();
|
||||
} catch (e) {
|
||||
callbackError(e, callback);
|
||||
}
|
||||
});
|
||||
|
||||
// Stop a service
|
||||
agentSocket.on("stopService", async (stackName: unknown, serviceName: unknown, callback) => {
|
||||
try {
|
||||
checkLogin(socket);
|
||||
|
||||
if (typeof (stackName) !== "string" || typeof (serviceName) !== "string") {
|
||||
throw new ValidationError("Stack name and service name must be strings");
|
||||
}
|
||||
|
||||
const stack = await Stack.getStack(server, stackName);
|
||||
await stack.stopService(socket, serviceName);
|
||||
callbackResult({
|
||||
ok: true,
|
||||
msg: `Service ${serviceName} stopped`
|
||||
}, callback);
|
||||
server.sendStackList();
|
||||
} catch (e) {
|
||||
callbackError(e, callback);
|
||||
}
|
||||
});
|
||||
|
||||
// getExternalNetworkList
|
||||
agentSocket.on("getDockerNetworkList", async (callback) => {
|
||||
try {
|
||||
|
|
|
@ -530,4 +530,24 @@ export class Stack {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
async startService(socket: DockgeSocket, serviceName: string) {
|
||||
const terminalName = getComposeTerminalName(socket.endpoint, this.name);
|
||||
const exitCode = await Terminal.exec(this.server, socket, terminalName, "docker", ["compose", "up", "-d", serviceName], this.path);
|
||||
if (exitCode !== 0) {
|
||||
throw new Error(`Failed to start service ${serviceName}, please check the terminal output for more information.`);
|
||||
}
|
||||
|
||||
return exitCode;
|
||||
}
|
||||
|
||||
async stopService(socket: DockgeSocket, serviceName: string): Promise<number> {
|
||||
const terminalName = getComposeTerminalName(socket.endpoint, this.name);
|
||||
const exitCode = await Terminal.exec(this.server, socket, terminalName, "docker", ["compose", "stop", serviceName], this.path);
|
||||
if (exitCode !== 0) {
|
||||
throw new Error(`Failed to stop service ${serviceName}, please check the terminal output for more information.`);
|
||||
}
|
||||
|
||||
return exitCode;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,20 @@
|
|||
<font-awesome-icon icon="terminal" />
|
||||
Bash
|
||||
</router-link>
|
||||
<button v-if="status !== 'running'"
|
||||
class="btn btn-primary me-2"
|
||||
:disabled="processing"
|
||||
@click="startService">
|
||||
<font-awesome-icon icon="play" class="me-1" />
|
||||
Start
|
||||
</button>
|
||||
<button v-if="status === 'running'"
|
||||
class="btn btn-danger me-2"
|
||||
:disabled="processing"
|
||||
@click="stopService">
|
||||
<font-awesome-icon icon="stop" class="me-1" />
|
||||
Stop
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -284,6 +298,12 @@ export default defineComponent({
|
|||
remove() {
|
||||
delete this.jsonObject.services[this.name];
|
||||
},
|
||||
startService() {
|
||||
this.$emit('start-service', this.name);
|
||||
},
|
||||
stopService() {
|
||||
this.$emit('stop-service', this.name);
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
|
|
@ -129,6 +129,9 @@
|
|||
:is-edit-mode="isEditMode"
|
||||
:first="name === Object.keys(jsonConfig.services)[0]"
|
||||
:status="serviceStatusList[name]"
|
||||
:processing="processing"
|
||||
@start-service="startService"
|
||||
@stop-service="stopService"
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
@ -786,6 +789,32 @@ export default {
|
|||
this.stack.name = this.stack?.name?.toLowerCase();
|
||||
},
|
||||
|
||||
startService(serviceName) {
|
||||
this.processing = true;
|
||||
|
||||
this.$root.emitAgent(this.endpoint, "startService", this.stack.name, serviceName, (res) => {
|
||||
this.processing = false;
|
||||
this.$root.toastRes(res);
|
||||
|
||||
if (res.ok) {
|
||||
this.requestServiceStatus(); // Refresh service status
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
stopService(serviceName) {
|
||||
this.processing = true;
|
||||
|
||||
this.$root.emitAgent(this.endpoint, "stopService", this.stack.name, serviceName, (res) => {
|
||||
this.processing = false;
|
||||
this.$root.toastRes(res);
|
||||
|
||||
if (res.ok) {
|
||||
this.requestServiceStatus(); // Refresh service status
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
|
Loading…
Add table
Reference in a new issue