Commit 4ea3c67b authored by Leo Iannacone's avatar Leo Iannacone

implemented debomatic status

parent ee4d988d
...@@ -72,6 +72,7 @@ server.listen(config.port, config.host, null, function (err) { ...@@ -72,6 +72,7 @@ server.listen(config.port, config.host, null, function (err) {
client.start(); client.start();
if (status.length > 0) if (status.length > 0)
client.send_status(status); client.send_status(status);
client.send_status_debomatic();
}); });
console.log('Debomatic-webui listening on %s:%d in %s mode', server.address().address, server.address().port, app.settings.env); console.log('Debomatic-webui listening on %s:%d in %s mode', server.address().address, server.address().port, app.settings.env);
......
...@@ -63,12 +63,29 @@ function __watch_distributions(socket) { ...@@ -63,12 +63,29 @@ function __watch_distributions(socket) {
}); });
} }
function __watch_pidfile(socket) {
fs.watchFile(config.debomatic.pidfile, {
persistent: false,
interval: 1007
},
function (curr, prev) {
var status_debomatic = {
"running": curr.ino !== 0 // if === 0 means pidfile does not exists
};
try {
socket.emit(socket.emit(config.events.broadcast.status_debomatic, status_debomatic));
} catch (err) {}
});
}
function Broadcaster(sockets, status) { function Broadcaster(sockets, status) {
__watch_status(sockets, status); __watch_status(sockets, status);
__watch_distributions(sockets); __watch_distributions(sockets);
__watch_pidfile(sockets);
return { return {
}; };
......
...@@ -181,6 +181,14 @@ function Client(socket) { ...@@ -181,6 +181,14 @@ function Client(socket) {
this.send_status = function (status) { this.send_status = function (status) {
socket.emit(_e.status, status); socket.emit(_e.status, status);
}; };
this.send_status_debomatic = function () {
fs.exists(config.debomatic.pidfile, function (exists) {
socket.emit(config.events.broadcast.status_debomatic, {
'running': exists
});
});
};
} }
module.exports = Client; module.exports = Client;
...@@ -67,7 +67,7 @@ config.web.preferences.debug = 0; // debug level - 0 means disabled ...@@ -67,7 +67,7 @@ config.web.preferences.debug = 0; // debug level - 0 means disabled
// DO NOT TOUCH these ones // DO NOT TOUCH these ones
config.version = '0.3.1'; config.version = '0.4.0';
// A simple function to quickly have // A simple function to quickly have
// get and set strings for client events // get and set strings for client events
...@@ -78,11 +78,18 @@ function _event_get_set(event_name) { ...@@ -78,11 +78,18 @@ function _event_get_set(event_name) {
}; };
} }
config.debomatic.pidfile = "/var/run/debomatic-" +
require('crypto')
.createHash('sha256')
.update(config.debomatic.path)
.digest('hex');
config.events = {}; config.events = {};
config.events.error = 'error'; config.events.error = 'error';
config.events.broadcast = {}; config.events.broadcast = {};
config.events.broadcast.distributions = 'distributions'; config.events.broadcast.distributions = 'distributions';
config.events.broadcast.status_update = 'status_update'; config.events.broadcast.status_update = 'status_update';
config.events.broadcast.status_debomatic = 'status_debomatic';
config.events.client = {}; config.events.client = {};
config.events.client.distribution_packages = _event_get_set('distribution_packages'); config.events.client.distribution_packages = _event_get_set('distribution_packages');
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
function Page_Generic() { function Page_Generic() {
var _e = config.events; var _e = config.events;
var status_debomatic = {};
function __get_status_html_id(status_data) { function __get_status_html_id(status_data) {
var result = 'status-' + status_data.status + '-' + status_data.distribution; var result = 'status-' + status_data.status + '-' + status_data.distribution;
...@@ -73,12 +74,22 @@ function Page_Generic() { ...@@ -73,12 +74,22 @@ function Page_Generic() {
var status = { var status = {
set: function (data_status) { set: function (data_status) {
if (!data_status) {
if (status_debomatic.running) {
$('#status .idle').show();
$('#status .norunning').hide();
} else {
$('#status .idle').hide();
$('#status .norunning').show();
}
} else {
$('#status ul').html(''); $('#status ul').html('');
if (data_status.length > 0) { if (data_status.length > 0) {
data_status.forEach(function (s) { data_status.forEach(function (s) {
status.append(s); status.append(s);
}); });
} }
}
}, },
append: function (status_data) { append: function (status_data) {
$('#status .idle').hide(); $('#status .idle').hide();
...@@ -107,8 +118,9 @@ function Page_Generic() { ...@@ -107,8 +118,9 @@ function Page_Generic() {
// and show idle label if necessary. // and show idle label if necessary.
setTimeout(function () { setTimeout(function () {
li.remove(); li.remove();
if ($('#status li').length === 0) if ($('#status li').length === 0) {
$('#status .idle').show(); status.set();
}
}, config.status.delay.remove + 2000); // more delay on remove html }, config.status.delay.remove + 2000); // more delay on remove html
}, config.status.delay.remove); }, config.status.delay.remove);
} else if (!status_data.hasOwnProperty('success')) { } else if (!status_data.hasOwnProperty('success')) {
...@@ -159,6 +171,12 @@ function Page_Generic() { ...@@ -159,6 +171,12 @@ function Page_Generic() {
status.update(package_status); status.update(package_status);
}); });
socket.on(_e.broadcast.status_debomatic, function (socket_status_debomatic) {
debug_socket('received', _e.broadcast.status_debomatic, socket_status_debomatic);
status_debomatic = socket_status_debomatic;
status.set();
});
socket.on(_e.error, function (error) { socket.on(_e.error, function (error) {
console.error('socket > ' + error); console.error('socket > ' + error);
}); });
......
...@@ -116,6 +116,10 @@ footer { ...@@ -116,6 +116,10 @@ footer {
margin-right: 10px; margin-right: 10px;
} }
#status .debomatic {
display: none;
}
#status .packages { #status .packages {
display: inline; display: inline;
} }
......
...@@ -5,7 +5,9 @@ ...@@ -5,7 +5,9 @@
Fork me on <a href="https://github.com/LeoIannacone/debomatic-webui">github</a> Fork me on <a href="https://github.com/LeoIannacone/debomatic-webui">github</a>
</small> </small>
<div id="status" class="clearfix"> <div id="status" class="clearfix">
<span class="label label-default">status:</span> <span class="idle text-muted">Idle</span> <span class="label label-default">status:</span>
<span class="debomatic idle text-muted">Idle</span>
<span class="debomatic norunning text-danger">Not running</span>
<ul class="packages list-inline"></ul> <ul class="packages list-inline"></ul>
</div> </div>
</footer> </footer>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment