mirror of
https://github.com/louislam/dockge.git
synced 2025-02-22 19:45:56 +00:00
add restart button
added restart service/container button as well as fixed start/stop buttons for correct statuses of healthy/unhealthy
This commit is contained in:
parent
cc12f7221e
commit
faa052933e
4 changed files with 59 additions and 6 deletions
|
@ -274,6 +274,25 @@ export class DockerSocketHandler extends AgentSocketHandler {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
agentSocket.on('restartService', async (stackName: unknown, serviceName: unknown, callback) => {
|
||||||
|
try {
|
||||||
|
checkLogin(socket);
|
||||||
|
|
||||||
|
if (typeof stackName !== 'string' || typeof serviceName !== 'string') {
|
||||||
|
throw new Error('Invalid stackName or serviceName');
|
||||||
|
}
|
||||||
|
|
||||||
|
const stack = await Stack.getStack(server, stackName, true);
|
||||||
|
await stack.restartService(socket, serviceName);
|
||||||
|
callbackResult({
|
||||||
|
ok: true,
|
||||||
|
msg: `Service ${serviceName} restarted`
|
||||||
|
}, callback);
|
||||||
|
} catch (e) {
|
||||||
|
callbackError(e, callback);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// getExternalNetworkList
|
// getExternalNetworkList
|
||||||
agentSocket.on("getDockerNetworkList", async (callback) => {
|
agentSocket.on("getDockerNetworkList", async (callback) => {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -535,7 +535,7 @@ export class Stack {
|
||||||
const terminalName = getComposeTerminalName(socket.endpoint, this.name);
|
const terminalName = getComposeTerminalName(socket.endpoint, this.name);
|
||||||
const exitCode = await Terminal.exec(this.server, socket, terminalName, "docker", ["compose", "up", "-d", serviceName], this.path);
|
const exitCode = await Terminal.exec(this.server, socket, terminalName, "docker", ["compose", "up", "-d", serviceName], this.path);
|
||||||
if (exitCode !== 0) {
|
if (exitCode !== 0) {
|
||||||
throw new Error(`Failed to start service ${serviceName}, please check the terminal output for more information.`);
|
throw new Error(`Failed to start service ${serviceName}, please check logs for more information.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return exitCode;
|
return exitCode;
|
||||||
|
@ -545,7 +545,17 @@ export class Stack {
|
||||||
const terminalName = getComposeTerminalName(socket.endpoint, this.name);
|
const terminalName = getComposeTerminalName(socket.endpoint, this.name);
|
||||||
const exitCode = await Terminal.exec(this.server, socket, terminalName, "docker", ["compose", "stop", serviceName], this.path);
|
const exitCode = await Terminal.exec(this.server, socket, terminalName, "docker", ["compose", "stop", serviceName], this.path);
|
||||||
if (exitCode !== 0) {
|
if (exitCode !== 0) {
|
||||||
throw new Error(`Failed to stop service ${serviceName}, please check the terminal output for more information.`);
|
throw new Error(`Failed to stop service ${serviceName}, please check logs for more information.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return exitCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
async restartService(socket: DockgeSocket, serviceName: string): Promise<number> {
|
||||||
|
const terminalName = getComposeTerminalName(socket.endpoint, this.name);
|
||||||
|
const exitCode = await Terminal.exec(this.server, socket, terminalName, "docker", ["compose", "restart", serviceName], this.path);
|
||||||
|
if (exitCode !== 0) {
|
||||||
|
throw new Error(`Failed to restart service ${serviceName}, please check logs for more information.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return exitCode;
|
return exitCode;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="shadow-box big-padding mb-3 container">
|
<div class="shadow-box big-padding mb-3 container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-7">
|
<div class="col-5">
|
||||||
<h4>{{ name }}</h4>
|
<h4>{{ name }}</h4>
|
||||||
<div class="image mb-2">
|
<div class="image mb-2">
|
||||||
<span class="me-1">{{ imageName }}:</span><span class="tag">{{ imageTag }}</span>
|
<span class="me-1">{{ imageName }}:</span><span class="tag">{{ imageTag }}</span>
|
||||||
|
@ -14,26 +14,33 @@
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-5">
|
<div class="col-7">
|
||||||
<div class="function">
|
<div class="function">
|
||||||
<router-link v-if="!isEditMode" class="btn btn-normal" :to="terminalRouteLink" disabled="">
|
<router-link v-if="!isEditMode" class="btn btn-normal" :to="terminalRouteLink" disabled="">
|
||||||
<font-awesome-icon icon="terminal" />
|
<font-awesome-icon icon="terminal" />
|
||||||
Bash
|
Bash
|
||||||
</router-link>
|
</router-link>
|
||||||
<button v-if="status !== 'running'"
|
<button v-if="status !== 'running' && status !== 'healthy'"
|
||||||
class="btn btn-primary me-2"
|
class="btn btn-primary me-2"
|
||||||
:disabled="processing"
|
:disabled="processing"
|
||||||
@click="startService">
|
@click="startService">
|
||||||
<font-awesome-icon icon="play" class="me-1" />
|
<font-awesome-icon icon="play" class="me-1" />
|
||||||
Start
|
Start
|
||||||
</button>
|
</button>
|
||||||
<button v-if="status === 'running'"
|
<button v-if="status === 'running' || status === 'healthy' || status === 'unhealthy'"
|
||||||
class="btn btn-danger me-2"
|
class="btn btn-danger me-2"
|
||||||
:disabled="processing"
|
:disabled="processing"
|
||||||
@click="stopService">
|
@click="stopService">
|
||||||
<font-awesome-icon icon="stop" class="me-1" />
|
<font-awesome-icon icon="stop" class="me-1" />
|
||||||
Stop
|
Stop
|
||||||
</button>
|
</button>
|
||||||
|
<button v-if="status === 'running' || status === 'healthy' || status === 'unhealthy'"
|
||||||
|
class="btn btn-warning me-2"
|
||||||
|
:disabled="processing"
|
||||||
|
@click="restartService">
|
||||||
|
<font-awesome-icon icon="sync" class="me-1" />
|
||||||
|
Restart
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -303,7 +310,11 @@ export default defineComponent({
|
||||||
},
|
},
|
||||||
stopService() {
|
stopService() {
|
||||||
this.$emit('stop-service', this.name);
|
this.$emit('stop-service', this.name);
|
||||||
|
},
|
||||||
|
restartService() {
|
||||||
|
this.$emit('restart-service', this.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -132,6 +132,7 @@
|
||||||
:processing="processing"
|
:processing="processing"
|
||||||
@start-service="startService"
|
@start-service="startService"
|
||||||
@stop-service="stopService"
|
@stop-service="stopService"
|
||||||
|
@restart-service="restartService"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -815,6 +816,18 @@ export default {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
restartService(serviceName) {
|
||||||
|
this.processing = true;
|
||||||
|
|
||||||
|
this.$root.emitAgent(this.endpoint, "restartService", this.stack.name, serviceName, (res) => {
|
||||||
|
this.processing = false;
|
||||||
|
this.$root.toastRes(res);
|
||||||
|
|
||||||
|
if (res.ok) {
|
||||||
|
this.requestServiceStatus(); // Refresh service status
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Add table
Reference in a new issue