npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

shync

v0.4.0

Published

Simple parallel server cluster management tool using ssh and scp

Downloads

70,260

Readme

shync

Simple parallel server cluster management tool for Node using ssh and scp. Specify an ssh or scp command and it will run on all servers in the cluster in parallel.

Installation

npm install shync

ssh

var Shync = require('shync').Shync;

var cluster = new Shync({
  domains: ['23.42.103.164',
            'mydomain.com'],
  user:    'ubuntu',
  keyLoc:  '/path/to/public/key',
  bypassFingerprint: true
});

cluster.run('node ~/stuff/important.js', function(err){
  if (err) return console.log(err);
  console.log('you\'ve done something important on many machines!');
});

scp

cluster.run('~/important.tar.gz', '~/stuff/important.tar.gz', function(err){
  if (err) return console.log(err);
  console.log('you\'ve done something important on many machines!');
});

Chaining commands

cluster.run('~/important.tar.gz', '~/stuff/important.tar.gz', function(err){
  if (err) return console.log(err);
    cluster.run('tar xzvf ~/stuff/important.tar.gz', function(err){
      if (err) return console.log(err);
        cluster.run('node ~/stuff/important.js', function(err){
          if (err) return console.log(err);
            console.log('you\'ve done something important on many machines!');
          }
        });
      }
    });
  }
});

Return codes and the err callback parameter

If a command was not successful, shync callbacks will receive the return code of the command that was run as the err paramater. shync treats the success of a command as "all or nothing." If the command was successful on all remote machines, null is returned to the callback. If even one machine returned a non 0 code, then the command as a whole is deemed to have failed and the non 0 code will be returned as the err param to the callback.

shync fails quickly if a remote machine returns a non 0 code. All outstanding connections to the remaining servers are severed, since their return codes are irrelevant now that a non 0 code has been received.

stdout and stderr

You can specify a function to be called with the stdout and/or stderr of the program you're running:


function stdout(out) {
  console.log(out);
}

function stderr(err) {
  console.log(err);
}

var cluster = new Shync({
  ...
  stdout: stdout,
  stderr: stderr
});

cluster.run('rm -rf /', cb);
// ec2-54-226-122-165.compute-1.amazonaws.com:STDERR: rm: it is dangerous to operate recursively on `/'
// ec2-54-226-122-165.compute-1.amazonaws.com:STDERR: rm: use --no-preserve-root to override this failsafe

cluster.run('ls -a ~', cb);
// ec2-54-226-122-165.compute-1.amazonaws.com:STDOUT: .  ..  .bash_history  .bashrc  .ssh

bypassFingerprint

var cluster = new Shync({
  ...
  bypassFingerprint: true
  ...
});

You know when you ssh from the command line into a brand new box, and you get this message:

$ ssh [email protected]
The authenticity of host 'example.com (23.20.102.179)' can't be established.
RSA key fingerprint is 2f:5d:69:26:e2:a0:23:53:f7:0a:21:51:0a:74:8a:49.
Are you sure you want to continue connecting (yes/no)?

bypassFingerprint: true stops this from happening.

Warning Use bypassFingerprint at your own risk.