Manage services and view logs.

This commit is contained in:
opi 2014-01-29 18:32:22 +01:00
parent ca6709172a
commit 5e366d0599
5 changed files with 162 additions and 0 deletions

View file

@ -494,6 +494,69 @@ app = Sammy('#main', function (sam) {
c.redirect('#/apps/'+ c.params['app']);
}
});
/**
* Services
*
*/
// All services status
sam.get('#/services', function (c) {
c.api('/service/status', function(data) { // ?
data2 = { 'services': [] }
$.each(data, function(k, v) {
v.name = k;
v.is_loaded = (v.loaded=='enabled') ? true : false;
v.is_running = (v.status=='running') ? true : false;
data2.services.push(v);
});
c.view('service_list', data2);
});
});
// Status & actions for a service
sam.get('#/services/:service', function (c) {
params = { 'names': c.params['service'] }
c.api('/service/status', function(data) { // ?
data2 = { 'service': data }
data2.service.name = c.params['service'];
data2.service.is_loaded = (data.loaded=='enabled') ? true : false;
data2.service.is_running = (data.status=='running') ? true : false;
store.clear('slide');
c.view('service_info', data2);
}, 'GET', params);
});
// Service log
sam.get('#/services/:service/log', function (c) {
params = { 'name': c.params['service'], 'number': 50 }
c.api('/service/log', function(data) { // ?
data2 = { 'logs': [], 'name': c.params['service'] }
$.each(data, function(k, v) {
data2.logs.push({name: k, log: v.join('\n')});
});
store.clear('slide');
c.view('service_log', data2);
}, 'GET', params);
});
// Enable/Disable & Start/Stop service
sam.get('#/services/:service/:action', function (c) {
if (confirm('Are you sure you want to '+ c.params['action'] +' '+ c.params['service'] +' ?')) {
params = { 'names': c.params['service'] }
c.api('/service/'+ c.params['action'], function(data) {
store.clear('slide');
c.redirect('#/services/'+ c.params['service']);
}, 'GET', params);
} else {
store.clear('slide');
c.redirect('#/services/'+ c.params['service']);
}
});
});

View file

@ -20,5 +20,10 @@
<span class="glyphicon glyphicon-chevron-right pull-right"></span>
<div class="clearfix"></div>
</a>
<a href="#/services" class="list-group-item slide">
<h4 class="pull-left list-group-item-heading">Services</h4>
<span class="glyphicon glyphicon-chevron-right pull-right"></span>
<div class="clearfix"></div>
</a>
</div>

52
views/service_info.ms Normal file
View file

@ -0,0 +1,52 @@
<div class="pull-left">
<a href="#/services" class="btn btn-default slide back"><span class="glyphicon glyphicon-chevron-left"></span> Services list</a>
</div>
<div class="clearfix"></div>
<div class="view-title">{{service.name}}</div>
<div class="br"></div>
<div class="container">
<h2>Status</h2>
{{#service}}
<div class="pull-left">
Loaded:
<span class="text-{{#is_loaded}}success{{/is_loaded}}{{^is_loaded}}danger{{/is_loaded}}">
{{loaded}}
</span>
<br>
Status:
<span class="text-{{#is_running}}success{{/is_running}}{{^is_running}}danger{{/is_running}}">
{{status}}
</span>
</div>
<div class="pull-right">
{{#is_loaded}}
<a href="#/services/{{name}}/disable" class="btn btn-danger slide back">
<span class="glyphicon glyphicon-remove"></span> Disable
</a>
{{/is_loaded}}
{{^is_loaded}}
<a href="#/services/{{name}}/enable" class="btn btn-success slide back">
<span class="glyphicon glyphicon-ok"></span> Enable
</a>
{{/is_loaded}}
{{#is_running}}
<a href="#/services/{{name}}/stop" class="btn btn-danger slide back">
<span class="glyphicon glyphicon-stop"></span> Stop
</a>
{{/is_running}}
{{^is_running}}
<a href="#/services/{{name}}/start" class="btn btn-success slide back">
<span class="glyphicon glyphicon-play"></span> Start
</a>
{{/is_running}}
<a href="#/services/{{name}}/log" class="btn btn-default slide back">
<span class="glyphicon glyphicon-book"></span> Log
</a>
</div>
{{/service}}
</div>

27
views/service_list.ms Normal file
View file

@ -0,0 +1,27 @@
<div class="pull-left">
<a href="#/" class="btn btn-default slide back"><span class="glyphicon glyphicon-chevron-left"></span> Menu</a>
</div>
<div class="clearfix"></div>
<div class="view-title">Services</div>
<div class="br"></div>
<div class="list-group">
{{#services}}
<a href="#/services/{{name}}" class="list-group-item slide service-{{name}}">
<span class="glyphicon glyphicon-chevron-right pull-right"></span>
<h3 class="list-group-item-heading">{{name}}</h3>
<div class="clearfix"></div>
<div class="list-group-item-text">
Loaded:
<span class="text-{{#is_loaded}}success{{/is_loaded}}{{^is_loaded}}danger{{/is_loaded}}">
{{loaded}}
</span>
<br>
Status:
<span class="text-{{#is_running}}success{{/is_running}}{{^is_running}}danger{{/is_running}}">
{{status}}
</span>
</div>
</a>
{{/services}}
</div>

15
views/service_log.ms Normal file
View file

@ -0,0 +1,15 @@
<div class="pull-left">
<a href="#/services/{{name}}" class="btn btn-default slide back"><span class="glyphicon glyphicon-chevron-left"></span>{{name}}</a>
</div>
<div class="clearfix"></div>
<div class="view-title">{{name}} log</div>
<div class="br"></div>
<div class="container">
{{#logs}}
<h2>{{name}}</h2>
<pre class="service-log">
{{log}}
</pre>
{{/logs}}
</div>