New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System Packages #16

Closed
groundwater opened this Issue Feb 16, 2014 · 7 comments

Comments

Projects
None yet
4 participants
@groundwater
Copy link
Contributor

groundwater commented Feb 16, 2014

I want to write a blog post about writing services for node-os. Feel free to add your input, or ask questions. I'll do my best to clarify things before making the post.

A system package manager is generally responsible for one of three types of packages.

  1. libraries
  2. executables
  3. services

In the case of node-os, a library would be any module which you'd install with npm install and then load with require(...). In a system like Ubuntu, a library would probably be a shared lib like openssl, or libxml2. Typically libraries are pre-compiled, meaning you only download the platform binary when installing. This is often much quicker, and less error prone that downloading and compiling source files.

npm handles pure-js libraries quite well, and node-os will not be changing how that works. To install a dependency to your module, call npm install $dep from within your modules directory. The story for c++ dependencies is a bit different, but I'm going to save that story for another time.

The second type of system package type are executable packages. These place executable files onto your PATH, allowing you to call them from the command line. The package.json allows you to specify executables quite easily.

{
  "name": "bender-rodriguez",
  "bin": {
    "destroy-all-humans": "destroy-all-humans.js"
  }
}

While npm install -g bender-rodriguez would install this package, and link it's executables, it's better on node-os to use npkg install bender-rodriguez.

Finally that brings us to services. Services are long-running daemons, like web-servers, databases, ssh-servers, etc. The package.json doesn't really have a service key, but it does have a scripts:start key. Define a service in your package.json file as such:

{
  "name": "planet-express-server",
  "scripts": {
    "start": "node server.js"
  }
}

You can start the package with npm start, but that isn't really a solution for starting services managed by the system. To install and run a service the node-os way

  1. install the package with npkg install $service
  2. start the package through init with npkg start $service

A job stanza will be generated by npkg and sent to init. Your service will be long-running, and restarted if it exits abnormally.

Creating services in detail will be yet another post.

@groundwater groundwater added the blog label Feb 16, 2014

@ljharb

This comment has been minimized.

Copy link

ljharb commented Feb 16, 2014

It seems like there's existing terminology for this - a module, or a global module. Defining preferGlobal: true in your package.json would make a module a global module. Typically they have a "bin" key, not a "start" key.

Why not just reuse the existing conventions and names?

"services" seems to be the new pattern, but a global module with a "start" key might be sufficient to differentiate?

@groundwater

This comment has been minimized.

Copy link
Contributor

groundwater commented Feb 16, 2014

Hey @ljharb thanks for the quick feedback.

I definitely think there is a mouthful of terminology here, and it probably needs to be unified. I'm trying to marry node terms with typical os/package-manager terms, and it's likely too much.

I like the term global module, and you're right they're typically only for modules with a bin key. I do think the service pattern is familiar to people; the Heroku node.js buildpack will consult the start script in order to generate the Procfile used to run the application. I just need a nice way of explaining it without throwing out too many new terms.

I think having npkg look for a preferGlobal key is also a good idea, I have noticed the distinction of when to use npkg vs npm is unclear to some. Just as npm complains when you install a global package locally, I could have npkg complain when you install a local package globally.

If you have a suggestion on a consistent terminology to march forward with I'm all ears.

@ljharb

This comment has been minimized.

Copy link

ljharb commented Feb 16, 2014

you could add a "service": true key to package.json - it's definitely extensible.

@groundwater

This comment has been minimized.

Copy link
Contributor

groundwater commented Feb 17, 2014

I don't want to introduce unnecessary tags into package.json, and the start script is already a standard means of identifying a service, or long-running application. It's also easy to explain the start script, since people are already familiar with npm start.

I think I'm going to explain that npkg is used to manage global modules only, and that there are two kinds of global modules used in node-os. The first are executable modules, and the second are service modules.

Hey @tekknolagi @EndangeredMassa do you want to weigh in about terminology. You've used node-os and presumably read my docs. Did you understand when to use npkg and when to use npm?

@tekknolagi

This comment has been minimized.

Copy link

tekknolagi commented Feb 17, 2014

I think I have a rough understanding of npm vs npkg, but I think it could
best be explained by an analog to another OS.

On Mon, Feb 17, 2014 at 2:07 AM, Jacob Groundwater <notifications@github.com

wrote:

I don't want to introduce unnecessary tags into package.json, and the
start script is already a standard means of identifying a service, or
long-running application. It's also easy to explain the start script,
since people are already familiar with npm start.

I think I'm going to explain that npkg is used to manage global modules
only, and that there are two kinds of global modules used in node-os. The
first are executable modules, and the second are service modules.

Hey @tekknolagi https://github.com/tekknolagi @EndangeredMassahttps://github.com/EndangeredMassado you want to weigh in about terminology. You've used node-os and
presumably read my docs. Did you understand when to use npkg and when
to use npm?

Reply to this email directly or view it on GitHubhttps://github.com//issues/16#issuecomment-35239271
.

@EndangeredMassa

This comment has been minimized.

Copy link

EndangeredMassa commented Feb 17, 2014

I think it makes sense to make it clear that npm is for local dependency mangement and npkg is for global modules. Global modules are those that offer bin keys. Services are global modules that offer scripts:start keys.

@groundwater

This comment has been minimized.

Copy link
Contributor

groundwater commented Feb 20, 2014

Thanks for the feedback, very much appreciated.

I wrote a draft post. Let's move the discussion over there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment