FAQ
Hi,

I've recently released the os-service module to npm:

https://www.npmjs.com/package/os-service

This module provides a consistent interface for installing node.js programs
as operating system services.

On Windows this module uses the WIN32 API to add and remove the service,
and to connect to the Windows Service Control Manager to run as a
background service when started using the Windows Service Controller
program, or "net start".

On Linux this module will add and remove start/stop scripts to/from the
"/etc/init.d" directory, and use "chkconfig" or "update-rc.d" to add and
remove the program. Then the "service ... start/stop/etc." command can be
used to control the service.

From the node.js programs perspective the same code is used on both
platforms, e.g.:

if (process.argv[2] == "--add") {
     service.add ("my-service", {programArgs: ["--run"]}, function(error){
        if (error)
           console.trace(error);
     });
} else if (process.argv[2] == "--remove") {
     service.remove ("my-service", function(error){
        if (error)
           console.trace(error);
     }););
} else if (process.argv[2] == "--run") {
     var logStream = fs.createWriteStream (process.argv[1] + ".log");

     service.run (logStream, function () {
         service.stop (0);
     });

     // Run your background program code here...
} else {
     // Show usage...
}

This can be useful when deploying an application across Windows and Linux,
in that no platform specific code needs to be written. If you have a
product built and packaged on a build server, during the install of the
product you could install one or more services from an installation script
once the installation directory had been selected and files copied in place
- assuming code similar to the above was in the my-service.js script quoted
below:

rem Windows
set DIR=c:\projects\my-service-project
%DIR%\node.exe %DIR%\my-service.js --add
net start my-service


# Linux
DIR=/projects/my-service-project
$DIR/node $DIR/my-service.js --add
service my-service start

This module is similar to the windows-service module I previously released:

https://www.npmjs.com/package/windows-service

The API's are almost identical, only the service add and remove API's are
slightly different in that they now take a callback. While they are not
100% compatible I have been sure to keep them aligned, since I think the
API was already in a good state, and I wanted to make it easy to migrate to
this module.

Although this module essentially replaces that module, I will continue to
support the windows-service module until there is no demand for it.

This is a new module, and the API for Linux is new. So there may be things
that make sense to Linux that are missing, e.g. which runlevels to
start/stop the service. So if there are any suggestions like this, or
feedback, it will be well received.

Steve

--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscribe@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/ae20bb07-47e3-4d9f-a7c4-0e52be1c004e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupnodejs @
categoriesnodejs
postedJan 7, '15 at 2:26p
activeJan 7, '15 at 2:26p
posts1
users1
websitenodejs.org
irc#node.js

1 user in discussion

Stephen Vickers: 1 post

People

Translate

site design / logo © 2018 Grokbase