微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Flightplan 远程执行命令

程序名称:Flightplan

授权协议: MIT

操作系统: 跨平台

开发语言: JavaScript

Flightplan 介绍

Flightplan 可以在本地或者远程主机上运行一序列的命令。这是一个 Node.js 库,用于执行应用发布和系统管理任务,类似 Python 的
Fabric

示例代码

// flightplan.js
var Flightplan = require('flightplan');

var tmpDir = 'pstadler-sh-' + new Date().getTime();

// configuration
plan.briefing({
    debug: false,
    destinations: {
        'staging': {
            host: 'staging.pstadler.sh',
            username: 'pstadler',
            agent: process.env.SSH_AUTH_SOCK
        },
        'production': [
            {
                host: 'www1.pstadler.sh',
                username: 'pstadler',
                agent: process.env.SSH_AUTH_SOCK
            },
            {
                host: 'www2.pstadler.sh',
                username: 'pstadler',
                agent: process.env.SSH_AUTH_SOCK
            }
        ]
    }
});

// run commands on localhost
plan.domestic(function(local) {
    local.log('Run build');
    local.exec('gulp build');

    local.log('copy files to remote host');
    var filesTocopy = '(git ls-files -z;find assets/public -type f -print0)';
    local.exec(filesTocopy + '|rsync --files-from - -avz0 --rsh="ssh"'
                + ' ./ [email protected]:/tmp/' + tmpDir);
});

// run commands on remote hosts (destinations)
plan.international(function(remote) {
    remote.log('Move folder to web root');
    remote.sudo('cp -R /tmp/' + tmpDir + ' ~', { user: 'www' });
    remote.rm('-rf /tmp/' + tmpDir);

    remote.log('Install dependencies');
    remote.sudo('npm --production --silent --prefix ~/'
                    + tmpDir + ' install ~/' + tmpDir, { user: 'www' });

    remote.log('Reload application');
    remote.sudo('ln -snf ~/' + tmpDir + ' ~/pstadler-sh', { user: 'www' });
    remote.sudo('pm2 reload pstadler-sh', { user: 'www' });
});

// run more commands on localhost afterwards
plan.domestic(function(local) { /* ... */ });
// ...or on remote hosts
plan.international(function(remote) { /* ... */ });

// executed if flightplan succeeded
plan.success(function() {
});

// executed if flightplan Failed
plan.disaster(function() {
});

// always executed after flightplan finished
plan.debriefing(function() {
});

Flightplan 官网

https://github.com/pstadler/flightplan

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐