npm / ndm Goto Github PK
View Code? Open in Web Editor NEWndm allows you to deploy OS-specific service-wrappers directly from npm-packages.
License: ISC License
ndm allows you to deploy OS-specific service-wrappers directly from npm-packages.
License: ISC License
I'd like to use exec-sync
to detect the appropriate Node.js bin, rather than having it set from CLI.
NodeSource uses lock file restart detection?
Continuing tangential discussions from #39 and #48.
Given an app, allow it to require('ndm')
and use it to implement its own service installer. The app could use a combination of it's own services.json for the interview phase and custom code for additional setup like creating necessary files/directories/users or whatever else such an installer might need to do.
I've done some commits to help forever to work as service manager for NodeOS, only keeps ndm to export services to its format :-) This would need to have render functions instead of templates, since the idea is to have all that config in a json file, with a list of objects one for each installed service, so an API is necesary. Where could we start looking for?
It would be awesome to support SmartOS, we've had a few people request it.
As we add more service wrappers, It would probably be smart to abstract things a bit, so that an integration can be written as a self contained module. Here's where a new service is added currently:
https://github.com/npm/ndm/blob/master/lib/config.js#L53
https://github.com/npm/ndm/blob/master/lib/config.js#L53
A couple thoughts about this approach:
prompt allow to define command line parameters so it doesn't do that questions later, it would be a good feature for ndm interview
so it doesn't block asking the configuration parameters.
On Ubuntu, an exception does not get raised when /etc/init/
cannot be written to.
It would be nice if ./node_modules/.bin was in the search path for bins.
I would love to be able to ship an npm package (with a service.json) that can be installed as a service, right away, like so:
npm install -g <my-package>
ndm generate <my-package>
Same goes for start/stop etc.
Currently one has to create a wrapper around services that are dependencies. I can understand this setup in a devops environment where you want to package together and distribute services, and in addition with specific args for ports etc.
But I think it would also be cool if in addition there was a more basic use case where you could just start an individual service directly from the npm package, without creating a wrapper at all.
If I'm not mistaken to pull this off you would need to allow top-level scripts in the service.json, right next to the top-level args and env.
I'd be more than willing to send a PR if this sounds like something that could get merged.
We should escape spaces in strings when generating run scripts, so that users don't have to quote their variables.
It would be nice to be able to prompt the user for variables when generating the service.json:
inquirer looks great for this.
Things would be a bit more DRY in service.json
if ndm would read from package.json in the absence of certain properties. Instead of this:
{
"newww": {
"module": "newww",
"description": "A total rewrite of npm-www using hapijs",
"scripts": {
"start": "node server.js"
},
"env": {
"PORT": "8081"
},
"args": {}
},
"newww2": {
"module": "newww",
"description": "A total rewrite of npm-www using hapijs",
"scripts": {
"start": "node server.js"
},
"env": {
"PORT": "8082"
},
"args": {}
},
"newww3": {
"module": "newww",
"description": "A total rewrite of npm-www using hapijs",
"scripts": {
"start": "node server.js"
},
"env": {
"PORT": "8083"
},
"args": {}
},
"newww4": {
"module": "newww",
"description": "A total rewrite of npm-www using hapijs",
"scripts": {
"start": "node server.js"
},
"env": {
"PORT": "8084"
},
"args": {}
}
}
I would prefer something like this:
{
"newww": {
"env": {
"PORT": "8081",
"NODE_ENV": "PRODUCTION"
}
},
"newww2": {
"env": {
"PORT": "8082",
"NODE_ENV": "PRODUCTION"
}
},
"newww3": {
"env": {
"PORT": "8083",
"NODE_ENV": "PRODUCTION"
}
},
"newww4": {
"env": {
"PORT": "8084",
"NODE_ENV": "PRODUCTION"
}
}
}
For personal reference, these spots in the code are related:
Line 217 in 386cb63
Line 271 in 386cb63
Took me a while to figure out it was 'ubuntu', 'centos' and 'initd', and the default 'linux' wasn't a thing.
It would be good to accept a full set of node flags, perhaps we could have a special suffix in the package.json for indicating flags that should be passed to the node bin?
Currently we require that a service.json file is present in modules which are installed using ndm. I think we should fallback to using the package.json if none is found. I suggest that we, by convention, look for the following fields in package.json:
{
"name": "package-name",
"description": "description of services",
"scripts": {
"start": "the-service-script"
},
"env": {
"PORT": 8000,
"uid": {
"description": "user to run as"
}
},
"args": {
"--foo": "args-instead-of-envs"
}
}
This reuses a lot of fields from package.json, which I think is awesome, and fits well with the discussion around service manifests started here: Service Descriptions
CC: @piranna, @seanewest, @groundwater
When an error happens starting/stopping/generating a script, we should exit with a non 0 code.
When a script is executed using ndm:
ndm run-script foo --path=./foo.txt
Paths are not resolved properly.
Hey @bcoe, nice to meet you. I ran across this project and it looks like we are solving very similar problems with npm. For the past few months, I've been building this: https://github.com/xtuple/xtuple-server.
I ended up building a semi-generic task-based deployment system. The one piece I've struggled to do well is the management of the deployed processes. If you have a minute, I'd be interested to see what you think. I can see some opportunity for combining forces, if that interests you.
Add support for crontab
on Linux as node-autostart does. This is more simple to manage that SystemD
.
An 'uninstall' command would be more simetric with the 'install' one and also make it orthogonal to NPM.
This is easy on ubuntu:
setuid ubuntu
.
Setting uid does not seem to work as well on Centos, I'm thinking perhaps we could put:
su user
in the script clause on Centos.
Log directory reported as:
/Users/benjamincoe/Library/Logs/ndm.log
Should be:
/Users/benjamincoe/Library/Logs/service-name.log
It would be nice if ndm's generated Upstart jobs allowed Upstart's logging to be used. Using the console log
stanza directs the process's stdout/stderr to /var/logs/upstart/.log with automatic log rotation.
Disclaimer: I wrote a rather opinionated blog post on how Node apps should log to stdout instead of managing log files.
Are there any plans (wishlist) for Windows support? Sorry if this was mentioned somewhere else, searched issues and didn't find much. Thanks.
.plist files already start on boot, but we should ensure that Centos/Ubuntu upstart scripts do the same.
Carrying from a tangent conversation on #48.
Upstart (and systemd) has support for connecting services as triggers. This could be used to model in Upstart the service dependency implied by listing multiple services inside services.json
. Foreman does this based on a Procfile, but ndm's services manifest looks like it is even more suited to this task.
Following is a workaround to make it possible for npme private modules to be self-installed.
Assuming private module is @private/myapp
var argv = require('yargs').argv
, ndm = require('ndm')('@private/myapp');
The docs say that you should use the name of the module inside the service.json, but without the prefix, the service.json is not found.
"myapp": {
"description": "myapp",
"module": "@private/myapp",
"scripts": {
"start": "node ./lib/myapp.js"
},
........
Without the "module" property the script change-directory (cd) command changes to an incorrect path.
It would be nice to have a .ndmrc file, so that users can place their service.json, logs, etc, in different locations.
It would be great for docker if scripts could be executed in the foreground.
It would be great to be able to use ndm on the containing module. I want to be able to use ndm to create service wrappers for the module itself, rather than modules in node_modules. Obviously I can use a wrapper module but this isn't a good solution for my use case.
To reproduce:
Create a service.json with an env
stanza that looks like this:
"env": { "MY_VAR": "i am a string with a lot of spaces in it" }
Generate upstart configs in an ubuntu environment. Observe that the service is invoked as something like this:
PORT=8080 MY_VAR=i am a string with a lot of spaces in it /usr/bin/nodejs server.js
Sadness ensues.
It would be awesome to be able to run a CLI command in the context of the variables set in service.json.
As common as Upstart@~0.6.5 (which lacks useful features from 1.4) support is, systemd looks like it is or will be taking over the role of "most common non-sysv-init" since Ubuntu and Debian are moving to it and almost every other distro already supports it.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.