-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdockerwait.js
23 lines (19 loc) · 1.03 KB
/
dockerwait.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*
This script waits for the master controller script to become available.
With orchestrators like Kubernetes, the master controller file may be fed in through
a volume container at runtime and so it is necessary to wait for it before launch.
*/
var fsUtil = require('socketcluster/fsutil');
var waitForFile = fsUtil.waitForFile;
var SOCKETCLUSTER_MASTER_DEFAULT_CONTROLLER = './server.js';
var masterControllerPath = process.env.SOCKETCLUSTER_MASTER_CONTROLLER || SOCKETCLUSTER_MASTER_DEFAULT_CONTROLLER;
var bootCheckInterval = Number(process.env.SOCKETCLUSTER_BOOT_CHECK_INTERVAL) || 200;
var bootTimeout = Number(process.env.SOCKETCLUSTER_CONTROLLER_BOOT_TIMEOUT) || 10000;
var bootStartTime = Date.now();
var errorMessage = `Failed to locate the master controller file at path ${masterControllerPath} ` +
`before SOCKETCLUSTER_CONTROLLER_BOOT_TIMEOUT`;
waitForFile(masterControllerPath, bootCheckInterval, bootStartTime, bootTimeout, errorMessage)
.catch((err) => {
console.error('> Boot error: ' + err.message);
process.exit(1);
});