Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
87: Add ability to pause/resume monitoring a service.
Browse files Browse the repository at this point in the history
  • Loading branch information
vishnu-kyatannawar committed Jun 25, 2017
1 parent ec6f822 commit a493634
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 7 deletions.
9 changes: 6 additions & 3 deletions lib/sentinel.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ var FIELDS_WHICH_MODIFICATION_TRIGGER_SERVICE_RESTART = [
'alertTo',
'pingServiceName',
'pingServiceOptions',
'warningThreshold'
'warningThreshold',
'isPaused'
];
var timeoutId = null;

Expand All @@ -34,7 +35,7 @@ Sentinel.prototype._findAdded = function (databaseServices, runningServices) {
databaseServices.forEach(function (s) {
if (!_.find(runningServices, function (rs) {
return rs.id == s.id;
})) {
}) && !s.isPaused) {
added.push(s);
}
});
Expand Down Expand Up @@ -112,7 +113,9 @@ Sentinel.prototype._tick = function () {
if (modifiedServices.length) {
modifiedServices.forEach(function (s) {
self.watchmen.removeService(s.id);
self.watchmen.addService(s);
if (!s.isPaused) {
self.watchmen.addService(s);
}
console.log('changes detected in service: ', s.name, '. Restarting...');
});
}
Expand Down
2 changes: 1 addition & 1 deletion lib/watchmen.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ WatchMen.prototype.startAll = function (options) {
}

this.services.forEach(function (service) {
if (!service.running) {
if (!service.running && !service.isPaused) {
setTimeout(function(){
self._launch(service);
service.running = true;
Expand Down
20 changes: 20 additions & 0 deletions webserver/public/js/controllers/services-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,26 @@
}
};

$scope.pause = function (id) {
if (confirm('Are you sure you want to pause this service?')) {
Service.pause({id: id}, function () {
reload(function () {
}, function () {
$scope.errorLoadingServices = "Error loading data from remote server";
});
});
}
};

$scope.resume = function (id) {
Service.resume({id: id}, function () {
reload(function () {
}, function () {
$scope.errorLoadingServices = "Error loading data from remote server";
});
});
};

reload(scheduleNextTick, loadServicesErrHandler);

});
Expand Down
16 changes: 16 additions & 0 deletions webserver/public/js/factories.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,22 @@
reset: {
method: 'POST',
url: '/api/services/:id/reset'
},

/**
* Pause service
*/
pause: {
method: 'POST',
url: '/api/services/:id/pause'
},

/**
* Resume service
*/
resume: {
method: 'POST',
url: '/api/services/:id/resume'
}

});
Expand Down
2 changes: 1 addition & 1 deletion webserver/public/less/service-list.less
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

.dropdown-menu{
padding:10px;
width:250px;
width:370px;
text-align: center;

.btn {
Expand Down
58 changes: 58 additions & 0 deletions webserver/routes/api-service-route.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,5 +168,63 @@ module.exports.getRoutes = function (storage) {
});
});

/**
* Pause service
*/

router.post('/services/:id/pause', requireAdmin, function (req, res) {
var id = req.params.id;
if (!id) {
return res.status(404).json({error: 'ID parameter not found'});
}
storage.getService(id, function (err, service) {
if (err) {
return res.status(500).json({error: err});
}

if (!service) {
return res.status(404).json({error: 'service not found'});
}

service.isPaused = 1;

storage.updateService(service, function (err, service) {
if (err) {
return res.status(500).json({error: err});
}
return res.json(service);
});
});
});

/**
* Resume service
*/

router.post('/services/:id/resume', requireAdmin, function (req, res) {
var id = req.params.id;
if (!id) {
return res.status(404).json({error: 'ID parameter not found'});
}
storage.getService(id, function (err, service) {
if (err) {
return res.status(500).json({error: err});
}

if (!service) {
return res.status(404).json({error: 'service not found'});
}

service.isPaused = 0;

storage.updateService(service, function (err, service) {
if (err) {
return res.status(500).json({error: err});
}
return res.json(service);
});
});
});

return router;
};
12 changes: 10 additions & 2 deletions webserver/views/service-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@
<a class="edit btn btn-default btn-xs" href="services/{{row.service.id}}/edit">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> edit
</a>
<button class="btn btn-warning btn-xs" ng-click="pause(row.service.id)" ng-if="!row.service.isPaused" >
<span class="glyphicon glyphicon-pause" aria-hidden="true"></span> Pause
</button>

<button class="btn btn-warning btn-xs" ng-click="resume(row.service.id)" ng-if="row.service.isPaused" >
<span class="glyphicon glyphicon-play" aria-hidden="true"></span> Resume
</button>
<button class="btn btn-danger btn-xs" ng-click="reset(row.service.id)">
<span class="glyphicon glyphicon-fire" aria-hidden="true"></span> reset
</button>
Expand All @@ -53,8 +60,9 @@
<% } %>

<td class="status" data-title="'Status'" sortable="'status.currentOutage'">
<span ng-if="row.status.currentOutage" class="label label-danger">offline</span>
<span ng-if="!row.status.currentOutage" class="label label-success">online</span>
<span ng-if="(!row.service.isPaused && row.status.currentOutage)" class="label label-danger">offline</span>
<span ng-if="(!row.service.isPaused && !row.status.currentOutage)" class="label label-success">online</span>
<span ng-if="row.service.isPaused" class="label label-info">Paused</span>
</td>

<td class="result-uptime" data-title="'last 24h'" sortable="'status.last24Hours.uptime'">
Expand Down

1 comment on commit a493634

@vishnu-kyatannawar
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding screenshot

pause

Please sign in to comment.