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

maiordomus

v0.1.5

Published

Multiple remote server management tool

Downloads

21

Readme

#Description Maiordomus is a command line application that allows to define multiple operation flows which can be executed locally or on one or many remote machines simultaneously. Check the project maiordomus-examples for real use case.

##Requirements To run it needs OpenSSH and node in the local machine and an OpenSSH server in the remote ones.

##Install npm install -g maiordomus

##Usage Maiordomus can be launched from the command line using the following arguments:

  • environment, mandatory, used to select the environment to work on. Environment must exist in the config file.
  • task, mandatory, used to choose wich task to perform on the given environment. Task must be defined in the maiordomus folder.
  • step, optional, used to specify wich step to execute, otherwise all the steps will be in the way they are defined.

###Setup Maiordomus expects to find a maiordomus folder on the root of your project containing a configuration file called config.js and tasks files. Eg:

myAwesomeWebApp
----maiordomus
--------config.js
--------task.js
----server.js
----package.json

####Configuration file This is an example of a configuration file:

/* MaiorDomus configuration */
module.exports = {
    // List of all the possible vbariables used to enrich commands
    variables: {
        logMessage: 'Application deployed'
    },
    // List of all the possible environments
    environments: {
        staging: {
            // list of hosts that compose the environment
            host: ['staging'],
            // Username used to connect
            username: 'nodeuser',
            // Private key used for authentication
            privateKey: require('fs').readFileSync('/path/to/key'),
        },
    	// environment name
        production: {
        	// list of hosts that compose the environment
            host: ['production.01', 'production.02'],
            // SSH port used to connect
            port: 2222,
            // Username used to connect
            username: 'ec2-user',
            // Private key used for authentication
            privateKey: require('fs').readFileSync('/path/to/key'),
            // Define enviornment specif values for variables
            variables: {
                logMessage: 'Application deployed in production'
            }
        }
    }
};

####Tasks files Tasks are used to define one or more steps. Take a look at this simple task:

// Require maiordomus
var geoffrey = require('maiordomus');

// Start defining the task and its steps sequentially
geoffrey
    // first step
    .step(
        'StopApplication', // Step name
        [ stopApplication ] // List of step actions
    ).step(
        'CleanAndStart', // Step name
        [ cleanLogs, startApplication ] // List of step actions
    );

// Function used in steps
function startApplication() {
    var maiordomus = this;
    maiordomus
        .connect()
        .exec('service myApp start')
        .done('<%= logMessage %>');
}

function stopApplication() {
    var maiordomus = this;
    maiordomus
        .connect()
        .exec('service myApp stop')
        .done();
}

function cleanLogs() {
    var maiordomus = this;
    maiordomus
        .connect()
        .exec('rm -f /logs/myApp/*.log')
        .done();
}

//Export the task
module.exports = geoffrey;

The task is pretty self explanatory, check this repo for more real use cases. Actions need to use the Maiordomus API to let the main application manage the steps and the actions flow in the right order; done must be called always at the end of each action.

####Templating Maiorodmus uses the lodash template syntax to enrich logs and commands passed to its API. It uses properties coming from the configuration.variables object extended with environment specific variables object.

##API Currently Maiordomus provides different API if it's used inside an action or inside the body of a task. Inside a task it just provides the step method that allow you to define a list of steps, all the other methods are available inside actions.

  • step (stepName, actions), defines a step of the task. Every step needs to have a name and a list of one or more actions defined.
  • log (message), output message on the current console.
  • connect (logMessage), opens an SSH connection to all the hosts configured for the current environment. If logMessage is passed it will be printed before starting the connection attempt.
  • disconnect (logMessage), close all the current SSH connections opened with the current environment hosts. If logMessage is passed it will be printed before starting the disconnect attempt.
  • exec (command), execute the given command on the remote machines or on the local one if no connections are openend. Eg:
function mixedExecute() {
    var maiordomus = this;
    maiordomus
        // executed locally
        .exec('ls -la /var/wwww')
        .connect()
        // executed remotely
        .exec('ls -la /var/www')
        .disconnect()
        // executed locally
        .exec('ls -la /var/www')
        .done();
}
  • get (remotePath, localPath, logMessage), downloads a remote file located in a remotePath to localPath using an SFTP connection. If logMessage is passed it will be printed before the download attempt.
  • put (localPath, remotePath, logMessage), uploads a local file located in localPath to remotePath on remote machines. If logMessage is passed it will be printed before the download attempt.
  • done (logMessage), closes the current action flow. Must be called in order to let Maiordomus know that the flow is terminated. If logMessage is passed it will be printed instead of the default Done message.