Skip to content

Commit

Permalink
emu-runner to save from shutdowns
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-roark committed Jun 5, 2014
1 parent f198af6 commit e9ae2d2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ In order to run `socket.io-computer` you must have the following
dependenices installed:

- `qemu`
- `vncsnapshot`
- `redis-server`

On the mac, all of the above are available on [homebrew](http://brew.sh/).
Expand All @@ -39,10 +38,10 @@ $ node app.js
$ node io.js

# qemu instance
$ COMPUTER_ISO=xp.iso COMPUTER_IMG=winxp.img node qemu.js
$ COMPUTER_ISO=winxp.iso COMPUTER_IMG=winxp.img node qemu.js

# emulator communication process
$ node emu.js
$ COMPUTER_IMG=winxp.img node emu-runner.js
```

Then point your browser to `http://localhost:5000`.
Expand Down
3 changes: 2 additions & 1 deletion computer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = Computer;
function Computer() {
if (!(this instanceof Computer)) return new Computer();
this.running = false;
this.img = process.env.COMPUTER_IMG || null;
}

Computer.prototype.__proto__ = Emitter.prototype;
Expand Down Expand Up @@ -68,7 +69,7 @@ Computer.prototype.run = function() {

// saves a snapshot of disk image to the given filename
Computer.prototype.snapshot = function(name) {
if (!this.running) return;
if (!this.running || !this.img) return;

var command = 'qemu-img create -f qcow2 -b' + this.img + ' ' + name;
exec(command, function(error, stdout, stderr) {
Expand Down
20 changes: 20 additions & 0 deletions emu-runner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var forever = require('forever-monitor');

function startEmu() {
var child = new (forever.Monitor)('emu.js', {
max: 1,
silent: false,
options: []
});

child.on('exit', function () {
console.log('THE EMULATOR DIED');
setTimeout(function() {
startEmu();
}, 500);
});

child.start();
}

startEmu();
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"socket.io": "1.0.0-pre4",
"socket.io-client": "1.0.0-pre4",
"socket.io-emitter": "0.1.0",
"socket.io-redis": "0.1.2"
"socket.io-redis": "0.1.2",
"forever-monitor": "~1.2.3"
}
}

0 comments on commit e9ae2d2

Please sign in to comment.