Spawn a process from a storage snapshot and continue to snapshot at regular intervals
Last updated a year ago by emilbayes .
UNLICENSED · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install snapshot-spawn 
SYNC missed versions from official npm registry.


Build Status

Spawn a process from a storage snapshot and continue to snapshot at regular intervals

npm install @hyperdivision/snapshot-spawn


const Spawn = require('@hyperdivision/snapshot-spawn')
const Snapshot = require('@hyperdivision/s3-snapshot')
const S3 = require('s3-storage')

const s3 = new S3('fs://fake-s3')
const snapshot = new Snapshot('data', 'data-snapshot.tar', s3)

const s = new Spawn('node', ['-e', `
  let tick = 0

  try {
    tick = Number(fs.readFileSync('data/tick'), 'utf-8') || 0
  } catch (_) {}

  setInterval(function () {
    console.log('tick', tick++)
    if (!fs.existsSync('data')) fs.mkdirSync('data')
    fs.writeFileSync('data/tick', '' + tick)
  }, 1000)
`], {
  interval: 3000

s.on('stdout', data => process.stdout.write(data))
s.on('stderr', data => process.stderr.write(data))

s.on('download', () => console.log('Downloading a snapshot'))
s.on('snapshot', () => console.log('Taking a snapshot'))


s = new Spawn(cmd, args, options)

Create a new instance.

  • cmd is the command you want to spawn.
  • args is the array of arguments you want to pass.

Options include

  snapshot: <s3-snapshot-instance>, // required
  interval: ..., // how often should it snapshot in ms? defaults to 24h
  rollbacks: 0 // how many rollback to previous versions should be attempted?


Kill the process with a signal. Waits for a pending snapshot to finish.

The PID of the running process.

s.on('stdout', data)

Emitted when there data from stdout.

s.on('stderr', data)

Emitted when there data from stderr.

s.on('error', err)

Emitted when a critical error happens.

s.on('exit', code)

Emitted when the process exits fully.


Emitted when a snapshot is being downloaded.


Emitted when a snapshot is being performed. Before a snapshot happens your process will be killed with SIGTERM.


Emitted when a process is spawned.


Emitted when a rollback is attempted.


Exit the process with this code (114) to attempt a rollback.

Current Tags

  • 1.0.1                                ...           latest (a year ago)

1 Versions

  • 1.0.1                                ...           a year ago
Maintainers (1)
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
Dev Dependencies (3)
Dependents (0)

Copyright 2014 - 2016 © |