Manage many unique environments for a single tenant server.
Clone this repo, then: npm install
Running node master.js
will start a REST API to manage a single tenant process.
These define how multienv
will work:
Default:
3434
The port on which to host the builtin REST
API.
Default:
5000
multienv
will create many processes, each bound to a new port.
Port assignment will take place by defining the PORT
variable for each new process.
The port variable assigned to each process is HOSTEDPORTS
incremented by one
every time a new process is created.
Default:
./envs
WORKER_ENV
should be a directory. multienv
will monitor this directory for
any changes. Each file represents the unique environment variables defined for
each managed process. Added, Updated, or Removed from WORKER_ENV
represents a process which multienv
will create, restart, or
kill, respectively.
- add file - creates, or add a new process with a new config
- change file - restarts, or update a process with a new config
- remove file - kills, or deletes an process
Here is an example .env
file:
CUSTOMCONNSTR_mongo_collection=myentries
MONGO_CONNECTION=mongodb://localhost/mytest
RES=7
Eg, the file can be sourced in bash to set environment variables in an active
shell from a file local.env
with the above contents using . local.env
.
Default:
../cgm-remote-monitor
WORKER_DIR
should be a path to a directory. The directory should the root of
a node js application with a file called server.js
. For each environment
multienv
knows about, it will start node server.js
with those environment
variables defined. Eg, for an env file called local.env
, this would be
similar to running (cd $WORKER_DIR ; . $WORKER_ENV/local.env; node server.js)
,
but all files in $WORKER_DIR
.
If WORKER_DIR
's application fails, multienv
will try to restart it up to 4
times, and then gives up.
There's a built-in REST API, of course, to manage basic CRUD operations. The
REST API edits and lists the *.env
text files in WORKER_ENV
. It can also
select them by name, or by running cluster id. It can also create new
environments, which cause new processes to start.
/cluster
returns a json description of all currently running processes.
/cluster/:id
Returns details of process by id
.
/history
/cluster
returns a json description of all processes seen by metaenvdir
.
/environs
returns a json description of all environments found in WORKER_ENV
.
/environs/:name
returns a json description of environment by name
. This is
the name of the environment file relative to WORKER_ENV
, sans .env
extension.
POST a json object to define a new environment.
/environs/:name
returns a json description of environment by name
.
This is the name of the environment file relative to WORKER_ENV
, sans .env
extension.
Returns new environment variables as a json object.
/environs/:name
- Delete (and stop a running process for) an environment.
This is the name of the environment file relative to WORKER_ENV
, sans .env
extension.
/environs/:name/env
This is the name
of the environment file relative to WORKER_ENV
, sans
.env
extension.
Get environment variables as a json object.
/environs/:name/env/:field
- retrieve value of a single environment variable.
This is the name
of the environment file relative to WORKER_ENV
, sans
.env
extension.
The field
is the name of the single environment variable.