ndm allows you to deploy OS-specific service-wrappers directly from npm-packages.
ndm makes it easy to deploy a complex service-oriented-architecture by allowing you to deploy OS-specific service-wrappers directly from an npm package.
ndm currently supports Centos, OS X, and Ubuntu.
Table of Contents:
npm install ndm -g
You might need to run that as root with
How to build an ndm-ready package:
sudo npm install ndm -g
npm install my-service-module --save
envsfor your server.
ndm can run a single services or a collection of services. It's structured like an npm package, with a package.json file listing its dependencies. Each service you want to run with ndm should be packaged as its own separate npm module that the ndm wrapper depends on. Then a service.json file describes how to run each service.
An ndm wrapper package looks like this:
wrapper/ package.json service.json logs/ node_modules/
A node-packaged service built for ndm can provide some hints in its package.json about how to run itself. Here's an example ndm-ready package.json:
environment field and its subfields.
environment.args is a map of arguments that should be passed to the ndm service.
ndm.env is a map of environment variables that should be passed to your ndm service.
The ndm wrapper must also have a service.json file, which describes how to run the services. Run
ndm init to generate service.json from your installed npm dependencies. The init script will copy default values from the
environment stanza in each service's package.json. You can then edit the defaults if you need to change anything.
Here's an example:
startscript is used.
%iis a place-holder for the process # if you're running multiple processes.
Defaults for all services are in the top-level
args fields. Each services can override and extend the defaults in its own options stanza.
To add new dependencies:
npm install <new-service> --save
To install your ndm-wrapped services, copy the package directory to your host system using whatever means you prefer. Then from inside the directory, run
On systems like Ubuntu, you'll need to run this as root so ndm has permission to add the upstart config file to
/etc/init. On OS X, you can run it as any user to create a local launch control script.
Command line arguments can be passed to the service wrapper at generation time, by appending them after
ndm install -- --verbose true
You can start and stop the services manually using your host's native daemon control:
initctl. Or you can use
ndm start and
ndm stop from inside an ndm wrapper directory to start & stop all the wrapped services.
All console.log and console.error output is recorded in the
logs/ directory, in files named
<service-name>.log. This is separate from whatever internally-managed logging the service might do.
Rather than providing set-in-stone default values, you can opt to interview your user. To interview a user for important variables, write your default values in this form:
ndm interview, a user will then be asked to fill in these values in an interactive manner:
Benjamins-MacBook-Air:ndm benjamincoe$ node ./bin/ndm.js interviewstarting interview:[?] url of front facing server: www.example.com[?] what environment should we run the app in: test[?] what do you think of dogs? I like 'em.
.ndmrc file to your home directory, to override ndm's default settings.
Variable names should be camel-case. As an example, the following
.ndmrc would change the default logging location:
; override ndm CLI variables by adding; them to a .ndmrc file. Variables should be; cammel case.logsDirectory=/foo/bar/logs
Rather than using the ndm bin to manage services, you can use the ndm API to create a self-installable service:
startscript, which is what ndm will run by default.
#!/usr/bin/env nodevar argv = argvndm = 'ndm-test';switchargv_0case 'install':ndm;break;case 'remove':ndm;break;case 'start':ndmstart;break;case 'restart':ndm;break;case 'stop':ndm;break;case 'list-scripts':ndm;break;case 'run-script':ndm;break;
ndm-test is published to npm, try it out:
npm install ndm-test -gndm-test installndm-test start
For each service in your service.json file, you can optionally set the following flags.
maxOldSpaceSize: sets the
--max-old-space-sizeflag to to
ndm is an experiment, based on ops challenges we've been facing at npm. This is a dot release. I'll be moving things around a lot in this library, as we use it for our own deployments.
ndm stanza is not officially supported by npm.