test
This commit is contained in:
parent
c38f23d50e
commit
b370169aaf
@ -110,10 +110,10 @@ swarm.on('connection', (peer) => {
|
|||||||
case 'dockerCommand':
|
case 'dockerCommand':
|
||||||
console.log(`[INFO] Executing Docker CLI command: ${parsedData.data}`);
|
console.log(`[INFO] Executing Docker CLI command: ${parsedData.data}`);
|
||||||
try {
|
try {
|
||||||
const exec = spawn('sh', ['-c', parsedData.data]); // Use `spawn` to execute the command
|
const exec = spawn('sh', ['-c', parsedData.data]); // Use `spawn` to execute the Docker command
|
||||||
|
|
||||||
exec.stdout.on('data', (output) => {
|
exec.stdout.on('data', (output) => {
|
||||||
console.log(`[DEBUG] Command output: ${output.toString()}`);
|
console.log(`[DEBUG] Command output: ${output.toString()}`); // Log the command output
|
||||||
peer.write(
|
peer.write(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
type: 'dockerOutput',
|
type: 'dockerOutput',
|
||||||
@ -124,7 +124,7 @@ swarm.on('connection', (peer) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
exec.stderr.on('data', (error) => {
|
exec.stderr.on('data', (error) => {
|
||||||
console.error(`[ERROR] Command error output: ${error.toString()}`);
|
console.error(`[ERROR] Command error output: ${error.toString()}`); // Log any errors
|
||||||
peer.write(
|
peer.write(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
type: 'dockerOutput',
|
type: 'dockerOutput',
|
||||||
@ -147,8 +147,10 @@ swarm.on('connection', (peer) => {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`[ERROR] Failed to execute command: ${error.message}`);
|
console.error(`[ERROR] Failed to execute command: ${error.message}`);
|
||||||
peer.write(
|
peer.write(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
error: `Failed to execute command: ${error.message}`
|
type: 'dockerOutput',
|
||||||
|
connectionId: parsedData.connectionId,
|
||||||
|
data: `[ERROR] Failed to execute command: ${error.message}`,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user