【文件属性】:
文件名称:远程执行命令Flightplan.zip
文件大小:75KB
文件格式:ZIP
更新时间:2022-08-05 21:30:46
开源项目
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"'
' ./ pstadler@pstadler.sh:/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
【文件预览】:
flightplan-master
----.travis.yml(2KB)
----.eslintrc(704B)
----bin()
--------fly.js(3KB)
----index.js(35B)
----docs()
--------generate.js(807B)
--------template.md.ejs(1KB)
----package.json(2KB)
----test()
--------test.logger.js(2KB)
--------test.flight.js(6KB)
--------test.flightplan.js(10KB)
--------test.utils.queue.js(2KB)
--------test.utils.js(2KB)
--------mocha.opts(16B)
--------test.transport.shell.js(13KB)
--------test.transport.js(12KB)
--------test.transport.ssh.js(12KB)
--------test.fly.js(4KB)
--------utils()
--------fixtures()
----LICENSE(1KB)
----package-lock.json(130KB)
----.gitignore(75B)
----lib()
--------index.js(13KB)
--------flight()
--------transport()
--------logger()
--------utils()
--------errors.js(2KB)
----README.md(20KB)
----.eslintignore(9B)
----.editorconfig(169B)