pm2啓動jenkins不存在tty的問題

問題

使用pm2管理jenkins, 直接啓動bash script, 運行一些命令時會遇到tty不存在的錯誤java

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進程時並無啓用ttybootstrap

解決方案

用js啓動進程, 而且在spawn的時候設置tty配置bash

例子app

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/ui

相關文章
相關標籤/搜索