Skip to content

Commit

Permalink
Check pre-conditions before starting the services #PF-142
Browse files Browse the repository at this point in the history
  • Loading branch information
rihernandez committed Aug 23, 2021
1 parent ff0ec9b commit e57f599
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
75 changes: 75 additions & 0 deletions etc/service_envs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
[
{
"module": "agents",
"env": [
"SIPPROXY_HOST",
"SIPPROXY_API_PORT",
"SIPPROXY_API_USERNAME",
"SIPPROXY_API_SECRET"
]
},
{
"module": "providers",
"env": [
"SIPPROXY_HOST",
"SIPPROXY_API_PORT",
"SIPPROXY_API_USERNAME",
"SIPPROXY_API_SECRET"
]
},
{
"module": "callmanager",
"env": [
"MS_TRUNK",
"MS_CONTEXT",
"MS_EXTENSION",
"MS_ARI_INTERNAL_URL",
"MS_ARI_USERNAME",
"MS_ARI_SECRET",
"SIPPROXY_HOST",
"SIPPROXY_API_PORT",
"SIPPROXY_API_USERNAME",
"SIPPROXY_API_SECRET"
]
},
{
"module": "dispatcher",
"env": [
"MS_ARI_INTERNAL_URL",
"MS_ARI_USERNAME",
"MS_ARI_SECRET",
"RECORDINGS_PATH"
]
},
{
"module": "domains",
"env": [
"SIPPROXY_HOST",
"SIPPROXY_API_PORT",
"SIPPROXY_API_USERNAME",
"SIPPROXY_API_SECRET"
]
},
{
"module": "numbers",
"env": [
"SIPPROXY_HOST",
"SIPPROXY_API_PORT",
"SIPPROXY_API_USERNAME",
"SIPPROXY_API_SECRET"
]
},
{
"module": "secrets",
"env": ["VAULT_ADDR", "SECRETS_POLICY"]
},
{
"module": "storage",
"env": ["FS_HOST", "FS_PORT", "FS_USERNAME", "FS_SECRET"]
},
{
"module": "voice",
"env": []
}
]

16 changes: 16 additions & 0 deletions mods/common/src/env_is_set.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import logger from "@fonos/logger";
const register = require("../../../etc/service_envs.json");

export default function assertEnvIsSet(name: string) {
const services = register.filter((service: any) => service.module === name);
for (let value of services) {
value.env.forEach(function (variable: string) {
if (!(variable in process.env)) {
logger.error(
`The environment variable ${variable} is required but was not found`
);
process.exit(1);
}
});
}
}
2 changes: 2 additions & 0 deletions mods/common/src/service_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* limitations under the License.
*/
import logger from "@fonos/logger";
import assertEnvIsSet from "./env_is_set";
const grpc = require("@grpc/grpc-js");
import {getServerCredentials} from "./trust_util";
const interceptor = require("@speedymonster/grpc-interceptors");
Expand Down Expand Up @@ -59,6 +60,7 @@ export default function run(
}

srvInfList.forEach((srvInf: ServiceInf) => {
assertEnvIsSet(srvInf.name)
server.addService(srvInf.service, srvInf.server);
logger.info(`@fonos/common service runner [added ${srvInf.name} service]`);
});
Expand Down

0 comments on commit e57f599

Please sign in to comment.