Socket
Socket
Sign inDemoInstall

background-service-runner

Package Overview
Dependencies
3
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    background-service-runner

A daemon runner utility for node, python, shell and other executable services. Can be configured to run a monitored or detached child process or groups of processes.


Version published
Weekly downloads
46
increased by2200%
Maintainers
1
Install size
5.43 MB
Created
Weekly downloads
 

Readme

Source

Background Service Runner


NPM version Build Status Dependency Status

A daemon runner utility for node, python, shell and other executable services. Can be configured to run a monitored or detached child process or groups of processes.

Overview

Background Service Runner provides support for running executables in the background as detached, independent processes or as fully monitored child processes. The typical use case is to create a short script to run a longer running service like an HTTP web service. It can also be used to start and stop groups of services with a single script.

Installation

npm install background-service-runner --save

Use

The following demonstrates a minimal run script that runs a job as a detached script.

var runner = require('background-service-runner').createDaemonRunner(),
    command = __dirname + '/Job.js',
    child = runner.start( command );
    
console.log('pid: ', child.pid);

By default the runner detaches from the child so that it may exit after spawning the child. If you want the runner to exit immediately after spawning the job, then invoke start/stop like this:

var child = runner.start();
console.log( 'child running on pid: ', child.pid );
runner.stop();

Examples

There is a test runner and executable in the examples directory. Invoke the test runner and observe the log file examples/job.log to see its entries.

Tests

Unit tests written in mocha/chai/should and run using grunt. All code tested with jshint.

make test

- or -

make watch

Mocks

The project exposes two mocks for testing.

  • MockSpawn
  • MockChild
  • MockDaemonRunner

See the existing tests for use, but generally you can use these mocks like this...

var MockSpawn = require('background-service-runner').mocks.MockSpawn;

...

var mock = new MockSpawn(),
	opts = {
		log:log,
		spawn:mock.spawn
	},
	runner = new DaemonRunner( opts );
	
var child = runner.start( 'mycommand', [ 'foo', 'bar' ] );

should.exist( child );
child.pid.should.be.above( 1000 );

Note: works in linux/unix but not tested in windows.


Copyright © 2014-2016, rain city software | Version 0.91.10

Keywords

FAQs

Last updated on 19 Feb 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc