Skip to content

Commit

Permalink
#581 Add adjecent servers (stac, tipg, titiler, titiler-pgstac) and p…
Browse files Browse the repository at this point in the history
…roxies to npm start
  • Loading branch information
tariqksoliman committed Sep 6, 2024
1 parent 1a5c437 commit 529747a
Show file tree
Hide file tree
Showing 18 changed files with 621 additions and 151 deletions.
94 changes: 94 additions & 0 deletions adjacent-servers/adjacent-servers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
require("dotenv").config();
const logger = require("../API/logger");
const { spawn } = require("child_process");

const IS_WINDOWS = /^win/i.test(process.platform) ? true : false;
const EXT = IS_WINDOWS ? ".bat" : ".sh";

const adjacentServers = [
{
name: "stac",
command: `cd adjacent-servers/stac/ && start-stac${EXT}`,
port: process.env.STAC_PORT || 8881,
env: "WITH_STAC",
},
{
name: "tipg",
command: `cd adjacent-servers/tipg/ && start-tipg${EXT}`,
port: process.env.TIPG_PORT || 8882,
env: "WITH_TIPG",
},
{
name: "titiler",
command: `cd adjacent-servers/titiler/ && start-titiler${EXT}`,
port: process.env.TITILER_PORT || 8883,
env: "WITH_TITILER",
},
{
name: "titiler-pgstac",
command: `cd adjacent-servers/titiler-pgstac/ && start-titiler-pgstac${EXT}`,
port: process.env.TITILER_PGSTAC_PORT || 8884,
env: "WITH_TITILER_PGSTAC",
},
];

const serverProcesses = [];
adjacentServers.forEach((s) => {
if (process.env[s.env] === "true") {
logger(
"info",
`Starting ${s.name} server on port ${s.port}...`,
"adjacent-servers"
);
let cmd = spawn(s.command, [s.port], { shell: true });
serverProcesses.push(cmd);

cmd.stdout.on("data", (data) => {
if (`${data}`.indexOf("running") != -1)
process.stdout.write(`${s.name} - ${data}`);
});

cmd.stderr.on("data", (data) => {
if (`${data}`.indexOf("running") != -1)
process.stdout.write(`${s.name} - ${data}`);
});

cmd.on("error", (err) => {
process.stdout.write(`${s.name} ERROR - ${err}`);
});
}
});

let running = true;

function killProcess() {
logger("info", `Terminating adjacent servers...`, "adjacent-servers");
serverProcesses.forEach((process) => {
process.kill();
});
logger(
"success",
`Successfully terminated all adjacent servers.`,
"adjacent-servers"
);
running = false;
}

process.on("SIGTERM", killProcess);
process.on("SIGINT", killProcess);
process.on("uncaughtException", function (e) {
logger(
"error",
`[uncaughtException] app will be terminated: ${e.stack}`,
"adjacent-servers"
);
killProcess();
});

function run() {
setTimeout(function () {
if (running) run();
}, 1000);
}

run();
7 changes: 7 additions & 0 deletions adjacent-servers/stac/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
POSTGRES_USER=
POSTGRES_PASS=
POSTGRES_DBNAME=
POSTGRES_HOST=localhost
POSTGRES_HOST_READER=localhost
POSTGRES_HOST_WRITER=localhost
POSTGRES_PORT=5432
3 changes: 3 additions & 0 deletions adjacent-servers/stac/start-stac.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:: ###############################################################################
:: STAC
dotenv run python -m uvicorn stac_fastapi.pgstac.app:app --port %1
4 changes: 4 additions & 0 deletions adjacent-servers/stac/start-stac.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
###############################################################################
# STAC
dotenv run python -m uvicorn stac_fastapi.pgstac.app:app --port $1
31 changes: 31 additions & 0 deletions adjacent-servers/tipg/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# DB_MAX_CONN_SIZE need to be at least the same size as WEB_CONCURRENCY
DB_MIN_CONN_SIZE=1
DB_MAX_CONN_SIZE=10
DB_MAX_QUERIES=10
DB_MAX_IDLE=10

WEB_CONCURRENCY=10

AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
CPL_TMPDIR=/tmp
GDAL_CACHEMAX=75%
GDAL_DISABLE_READDIR_ON_OPEN=EMPTY_DIR
GDAL_HTTP_MERGE_CONSECUTIVE_RANGES=YES
GDAL_HTTP_MULTIPLEX=YES
GDAL_HTTP_VERSION=2

PYTHONWARNINGS=ignore
VSI_CACHE=TRUE
VSI_CACHE_SIZE=536870912

MOSAIC_CONCURRENCY=1
DEBUG=TRUE

TITILER_PGSTAC_API_DEBUG=TRUE

POSTGRES_USER=
POSTGRES_PASS=
POSTGRES_DBNAME=
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
3 changes: 3 additions & 0 deletions adjacent-servers/tipg/start-tipg.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
: ###############################################################################
:: tipg
dotenv run python -m uvicorn tipg.main:app --port %1
4 changes: 4 additions & 0 deletions adjacent-servers/tipg/start-tipg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
###############################################################################
# tipg
dotenv run python -m uvicorn tipg.main:app --port $1
31 changes: 31 additions & 0 deletions adjacent-servers/titiler-pgstac/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# DB_MAX_CONN_SIZE need to be at least the same size as WEB_CONCURRENCY
DB_MIN_CONN_SIZE=1
DB_MAX_CONN_SIZE=10
DB_MAX_QUERIES=10
DB_MAX_IDLE=10

WEB_CONCURRENCY=10

AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
CPL_TMPDIR=/tmp
GDAL_CACHEMAX=75%
GDAL_DISABLE_READDIR_ON_OPEN=EMPTY_DIR
GDAL_HTTP_MERGE_CONSECUTIVE_RANGES=YES
GDAL_HTTP_MULTIPLEX=YES
GDAL_HTTP_VERSION=2

PYTHONWARNINGS=ignore
VSI_CACHE=TRUE
VSI_CACHE_SIZE=536870912

MOSAIC_CONCURRENCY=1
DEBUG=TRUE

TITILER_PGSTAC_API_DEBUG=TRUE

POSTGRES_USER=
POSTGRES_PASS=
POSTGRES_DBNAME=
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
4 changes: 4 additions & 0 deletions adjacent-servers/titiler-pgstac/start-titiler-pgstac.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
:: ###############################################################################
:: TiTiler-pgSTAC
dotenv run python -m uvicorn titiler.pgstac.main:app --port %1

4 changes: 4 additions & 0 deletions adjacent-servers/titiler-pgstac/start-titiler-pgstac.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
###############################################################################
# TiTiler-pgSTAC
dotenv run python -m uvicorn titiler.pgstac.main:app --port $1
Empty file.
3 changes: 3 additions & 0 deletions adjacent-servers/titiler/start-titiler.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:: ###############################################################################
:: TiTiler
dotenv run python -m uvicorn titiler.application.main:app --port %1
4 changes: 4 additions & 0 deletions adjacent-servers/titiler/start-titiler.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
###############################################################################
# TiTiler
dotenv run python -m uvicorn titiler.application.main:app --port $1
Loading

0 comments on commit 529747a

Please sign in to comment.