Compare commits

...

1 Commits
main ... main

Author SHA1 Message Date
heckeralt cc326e054a Update start-linux.js 2024-09-20 16:32:08 -04:00
1 changed files with 28 additions and 4 deletions

View File

@ -4,7 +4,31 @@ let makedisk = "qemu-img create vm.img 30G" // make a 30GB disk
let qemucmd = "qemu-system-x86_64 -vnc :1 -m 1G -hda vm.img" let qemucmd = "qemu-system-x86_64 -vnc :1 -m 1G -hda vm.img"
child.execSync(makedisk) child.execSync(makedisk)
child.execSync(qemucmd) child.execSync(qemucmd)
http.createServer(function (req, res) { const server = http.createServer((req, res) => {
res.write('Server running at IP 127.0.0.1:5901 (VNC)'); //write a response to the client // Check if the request is a POST to /stop
res.end(); //end the response if (req.method === 'POST' && req.url === '/stop') {
}).listen(8080); //the server object listens on port 8080 // Execute the pkill command to stop Node.js processes
exec('pkill qemu*', (error, stdout, stderr) => {
if (error) {
console.error(`Error executing command: ${error.message}`);
res.writeHead(500);
res.end(JSON.stringify({ message: 'Failed to stop the server' }));
return;
}
console.log('QEMU processes terminated');
res.writeHead(200);
res.end(JSON.stringify({ message: 'Server is stopping' }));
});
} else {
// Handle 404 for other routes
res.writeHead(404);
res.end(JSON.stringify({ message: 'Not Found' }));
}
});
// Start the server on port 3000
const PORT = 8080;
server.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
console.log("QEMU and FreeVM are running. VNC into it using 127.0.0.1 to VNC into it and go to localhost:8080/stop to stop the VM.")
});