Skip to content

Commit ba997d3

Browse files
Merge branch 'film42-gt/stop_on_elastalert_exit' into develop
2 parents dce8fc1 + 411da13 commit ba997d3

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/controllers/process/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export default class ProcessController {
99

1010
constructor() {
1111
this._elastalertPath = config.get('elastalertPath');
12+
this._onExitCallbacks = [];
1213
this._status = Status.IDLE;
1314

1415
/**
@@ -18,6 +19,10 @@ export default class ProcessController {
1819
this._process = null;
1920
}
2021

22+
onExit(onExitCallback) {
23+
this._onExitCallbacks.push(onExitCallback);
24+
}
25+
2126
get status() {
2227
return this._status;
2328
}
@@ -112,6 +117,12 @@ export default class ProcessController {
112117
this._status = Status.ERROR;
113118
}
114119
this._process = null;
120+
121+
this._onExitCallbacks.map(function(onExitCallback) {
122+
if (onExitCallback !== null) {
123+
onExitCallback();
124+
}
125+
});
115126
});
116127

117128
// Set listener for ElastAlert error

src/elastalert_server.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ export default class ElastalertServer {
6969
self._fileSystemController = new FileSystem();
7070
self._processController = new ProcessController();
7171
self._processController.start();
72+
self._processController.onExit(function() {
73+
// If the elastalert process exits, we should stop the server.
74+
process.exit(0);
75+
});
7276

7377
self._rulesController = new RulesController();
7478
self._templatesController = new TemplatesController();

0 commit comments

Comments
 (0)