2018-11-07 12:05:14 -07:00
|
|
|
const semver = require('semver');
|
|
|
|
const engines = require('./package.json').engines;
|
|
|
|
|
|
|
|
const version = engines.node;
|
|
|
|
if (!semver.satisfies(process.version, version)) {
|
2020-08-01 01:36:20 -07:00
|
|
|
console.log(`\t\tZigbee2MQTT requires node version ${version}, you are running ${process.version}!\n`); // eslint-disable-line
|
2018-11-07 12:05:14 -07:00
|
|
|
}
|
2018-04-09 08:37:21 -07:00
|
|
|
|
2020-07-23 10:17:26 -07:00
|
|
|
// Validate settings
|
|
|
|
const settings = require('./lib/util/settings');
|
|
|
|
const errors = settings.validate();
|
|
|
|
if (errors.length > 0) {
|
|
|
|
console.log(`\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`);
|
|
|
|
console.log(' READ THIS CAREFULLY\n');
|
|
|
|
console.log(`Refusing to start because configuration is not valid, found the following errors:`);
|
|
|
|
for (const error of errors) {
|
|
|
|
console.log(`- ${error}`);
|
|
|
|
}
|
|
|
|
console.log(`\nIf you don't know how to solve this, read https://www.zigbee2mqtt.io/information/configuration.html`);
|
|
|
|
console.log(`\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n`);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
2018-11-07 12:05:14 -07:00
|
|
|
const Controller = require('./lib/controller');
|
2018-04-18 09:25:40 -07:00
|
|
|
const controller = new Controller();
|
|
|
|
controller.start();
|
2018-04-14 07:17:25 -07:00
|
|
|
|
2018-04-08 06:33:47 -07:00
|
|
|
process.on('SIGINT', handleQuit);
|
2019-03-24 06:27:49 -07:00
|
|
|
process.on('SIGTERM', handleQuit);
|
2018-04-08 06:00:36 -07:00
|
|
|
|
2019-05-20 11:43:25 -07:00
|
|
|
let stopping = false;
|
|
|
|
|
2018-04-08 06:33:47 -07:00
|
|
|
function handleQuit() {
|
2019-05-20 11:43:25 -07:00
|
|
|
if (!stopping) {
|
|
|
|
stopping = true;
|
2019-09-09 10:48:09 -07:00
|
|
|
controller.stop();
|
2019-05-20 11:43:25 -07:00
|
|
|
}
|
2018-05-17 08:20:46 -07:00
|
|
|
}
|