services.printer/script/deploy-auth-check.cjs
liufumingren c5bd7138e8 feat: 添加蓝绿部署发布脚本系统
- 蓝绿部署 (v1/v2 双实例, 端口 4051/4052)

- 部署预检、远程部署、回滚

- 版本追踪、Git 安全 Hook

- Nginx upstream 自动切换
2026-07-25 01:31:13 +08:00

43 lines
1.3 KiB
JavaScript

'use strict';
const { spawnSync } = require('node:child_process');
const { loadDeployConfig } = require('./deploy-lib.cjs');
function main() {
const config = loadDeployConfig('production');
const args = [ '-vv' ];
args.push('-p', String(config.port));
args.push('-i', config.privateKeyPath);
for (const option of config.sshOptions) {
args.push('-o', option);
}
args.push(`${config.username}@${config.host}`);
args.push('echo AUTH_CHECK_OK');
const result = spawnSync('ssh', args, {
encoding: 'utf8',
stdio: 'pipe',
shell: false,
});
const text = `${result.stdout || ''}\n${result.stderr || ''}`;
const summary = {
keyOffered: /Offering public key:/i.test(text) || /Will attempt key:/i.test(text),
keyAccepted: /Authenticated to .* using "publickey"/i.test(text) || /AUTH_CHECK_OK/i.test(text),
authFailed: /Permission denied|Authentication failed/i.test(text),
hostKeyFailed: /Host key verification failed|REMOTE HOST IDENTIFICATION HAS CHANGED/i.test(text),
networkFailed: /Connection timed out|No route to host|Connection refused|Could not resolve hostname|Operation timed out/i.test(text),
};
console.log(JSON.stringify(summary, null, 2));
if (summary.keyAccepted) {
process.exit(0);
}
process.exit(1);
}
main();