System Packages

Image
@groundwater

08:40 - 16 Feb 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.


7 Comments

NodeOS is made possible by its many contributors around the world. Source code licensed under the MIT license.

Made with ❤️
and 🍺