Skip to content

Instantly share code, notes, and snippets.

Last active Apr 8, 2016
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);
}).listen(process.env.port || 8080);
var timerId;
var actions = {
start: function(req, res){
if (err) console.log(err);
// shutdown after 15 minutes of inactivity
if (timerId){
timerId = setTimeout(actions.stop, 15 * 60 * 1000);
stop: function(req, res){
if (err) console.log(err);
timerId = undefined;
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