Skip to content

Instantly share code, notes, and snippets.

@rlemon

rlemon/server.js Secret

Created June 10, 2014 21:00
Show Gist options
  • Save rlemon/66c8fcdb07f408b0608a to your computer and use it in GitHub Desktop.
Save rlemon/66c8fcdb07f408b0608a to your computer and use it in GitHub Desktop.
var sys = require('sys')
var exec = require('child_process').exec;
var fs = require('fs');
var filepath = "/home/root/count.txt";
read();
function read() {
fs.readFile(filepath, function( err, data ) {
if( err ) {
console.log( "read error" , err );
return;
}
write(parseInt(data.toString(), 10));
});
}
function write(count) {
fs.writeFile(filepath, count+1, function(err) {
if( err ) {
console.log( "read error" , err );
return;
}
shutdown();
}
}
function shutdown() {
exec("shutdown -r now", function puts(error, stdout, stderr) {
console.log( stdout, stderr );
sys.puts(stdout);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment