Compare commits

...

2 Commits
main ... main

Author SHA1 Message Date
Guest 24897 cf0be8da47 Update start-linux.js 2024-09-20 16:58:39 -04:00
Guest 24897 6271ac2ba8 Update start-linux.js 2024-09-20 15:53:03 -04:00
1 changed files with 29 additions and 5 deletions

View File

@ -1,10 +1,34 @@
const http = require('http');
const child = require("child_process");
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 -accel kvm"
child.execSync(makedisk)
child.execSync(qemucmd)
http.createServer(function (req, res) {
res.write('Server running at IP 127.0.0.1:5901 (VNC)'); //write a response to the client
res.end(); //end the response
}).listen(8080); //the server object listens on port 8080
const server = http.createServer((req, res) => {
// Check if the request is a POST to /stop
if (req.method === 'POST' && req.url === '/stop') {
// 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.")
});