2015-07-20 00:09:47 -07:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
2018-01-19 19:26:45 +01:00
|
|
|
var database = require('./src/database.js');
|
|
|
|
|
|
2019-03-01 14:40:28 -08:00
|
|
|
var crashNotifier = require('./src/crashnotifier.js');
|
2015-09-07 11:18:44 -07:00
|
|
|
|
2019-01-19 13:23:49 +01:00
|
|
|
// This is triggered by systemd with the crashed unit name as argument
|
2015-09-07 11:18:44 -07:00
|
|
|
function main() {
|
2019-01-19 13:23:49 +01:00
|
|
|
if (process.argv.length !== 3) return console.error('Usage: crashnotifier.js <unitName>');
|
2015-09-07 11:18:44 -07:00
|
|
|
|
2019-01-19 13:23:49 +01:00
|
|
|
var unitName = process.argv[2];
|
|
|
|
|
console.log('Started crash notifier for', unitName);
|
2015-09-07 21:10:00 -07:00
|
|
|
|
2019-01-19 13:23:49 +01:00
|
|
|
// eventlog api needs the db
|
2018-01-19 19:26:45 +01:00
|
|
|
database.initialize(function (error) {
|
|
|
|
|
if (error) return console.error('Cannot connect to database. Unable to send crash log.', error);
|
|
|
|
|
|
2019-03-01 14:40:28 -08:00
|
|
|
crashNotifier.sendFailureLogs(unitName, function (error) {
|
|
|
|
|
if (error) console.error(error);
|
|
|
|
|
|
|
|
|
|
process.exit();
|
|
|
|
|
});
|
2018-01-19 19:26:45 +01:00
|
|
|
});
|
2015-09-07 11:18:44 -07:00
|
|
|
}
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2015-09-07 11:18:44 -07:00
|
|
|
main();
|