forked from kevin-roark/socket.io-computer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qemu.js
60 lines (50 loc) · 1.48 KB
/
qemu.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
var spawn = require('child_process').spawn;
var join = require('path').join;
var debug = require('debug')('computer:qemu');
if (!process.env.COMPUTER_ISO) {
console.log('You must specify the ENV variable `COMPUTER_ISO` ' +
'to location of iso file to broadcast.');
process.exit(1);
}
if (!process.env.COMPUTER_IMG) {
console.log('Must specificy the ENV variable `COMPUTER_IMG` ' +
'to location of disk image to use');
process.exit(1);
}
process.title = 'socket.io-computer-qemu';
var displayNum = process.env.COMPUTER_DISPLAY || '0';
var hostName = process.env.COMPUTER_VNC_HOST || '127.0.0.1';
var tcp = process.env.COMPUTER_TCP || '127.0.0.1:4444';
// iso
var iso = process.env.COMPUTER_ISO;
if ('/' != iso[0]) iso = join(process.cwd(), iso);
debug('iso %s', iso);
// img
var img = process.env.COMPUTER_IMG;
if ('/' != img[0]) img = join(process.cwd(), img);
debug('img %s', img);
init(img, iso);
function init(img, iso) {
var command = 'qemu-system-x86_64';
var args = [
'-m', '1024',
'-vnc', hostName + ':' + displayNum,
'-net', 'nic,model=rtl8139',
'-net', 'user',
'-usbdevice', 'tablet',
'-hda', img,
'-cdrom', iso,
'-monitor', 'tcp:' + tcp + ',server,nowait',
'-boot', 'c'
];
var options = {
stdio: 'inherit'
};
var instance = spawn(command, args, options);
instance.on('close', function(code) {
debug(new Date + ' - qemu closed with code: ' + code);
setTimeout(function() {
init(img, iso);
}, 500);
});
}