Skip to content

Instantly share code, notes, and snippets.

@richorama richorama/package.json
Last active Apr 8, 2016

Embed
What would you like to do?
A github service hook to start a VM, and shut it down after 15 minutes of inactivity
{
"name": "vmstartstop",
"version": "0.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"author": "",
"license": "MIT",
"dependencies": {
"azure": "~0.7.18"
}
}
var subscriptionId = "xxx";
var hostedService = "hosted_service";
var deploymentId = "deployment_name";
var roleInstance = "role_instance_name";
var azure = require('azure');
var sms = azure.createServiceManagementService(subscriptionId,{keyfile:"./mycert.pem",certfile:"./mycert.pem"});
require('http').createServer(function(req, res){
var path = req.url.replace('/', '');
if (path && actions[path]) actions[path](req, res);
res.end();
}).listen(process.env.port || 8080);
var timerId;
var actions = {
start: function(req, res){
sms.startRole(hostedService,deploymentId,roleInstance,function(err,data){
if (err) console.log(err);
console.log(data.body);
});
// shutdown after 15 minutes of inactivity
if (timerId){
clearTimeout(timerId);
}
timerId = setTimeout(actions.stop, 15 * 60 * 1000);
},
stop: function(req, res){
sms.shutdownRole(hostedService,deploymentId,roleInstance,true,function(err,data){
if (err) console.log(err);
console.log(data.body);
});
timerId = undefined;
}
};
@danmiser

This comment has been minimized.

Copy link

danmiser commented Apr 8, 2016

This used to work for me, but Azure must have updated something and this no longer works. Not exactly sure when the change of behavior occurred. I had set this up probably almost 2 years ago. Are you seeing that this still works? I'm using a Classic VM if that matters. Thanks for the gist!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.