pm2启动jenkins不存在tty的问题

问题

使用pm2管理jenkins, 直接启动bash script, 运行一些命令时会遇到tty不存在的错误

child_process.js:120
  p.open(fd);
    ^

Error: ENOTTY: inappropriate ioctl for device, uv_pipe_open
    at Object._forkChild (child_process.js:120:5)
    at setupChildProcessIpcChannel (internal/bootstrap/pre_execution.js:75:30)
    at prepareMainThreadExecution (internal/bootstrap/pre_execution.js:11:3)
    at internal/main/run_main_module.js:11:1

这主要是因为pm2启动jenkins进程时并没有启用tty

解决方案

用js启动进程, 并且在spawn的时候设置tty配置

例子

let spawn = require("child_process").spawn;
spawn(
  "/usr/bin/java",
  ["-jar", "/Applications/Jenkins/jenkins.war"],
  { stdio: [0, 1, 2] }
);

参考资料:  http://derpturkey.com/retain-tty-when-using-child_proces-spawn/

原文地址:https://www.cnblogs.com/dabaopku/p/10566616.html