[{"data":1,"prerenderedAt":1045},["ShallowReactive",2],{"post-\u002Fblog\u002F2026-09-26-ssh-tty-sighup-daemons":3,"surround-\u002Fblog\u002F2026-09-26-ssh-tty-sighup-daemons":1038},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"tags":11,"body":16,"_type":1032,"_id":1033,"_source":1034,"_file":1035,"_stem":1036,"_extension":1037},"\u002Fblog\u002F2026-09-26-ssh-tty-sighup-daemons","blog",false,"","主节点上的守护进程没了，ssh -tt 嫌疑最大","从 mac 经 ssh -tt 透传 cluster start all 以后，主节点本机起的三个守护进程没了。改成 ssh -n 以后验证通过，但这个解释还有几处对不上。","2026-09-26",[12,13,14,15],"SSH","Linux","运维","问题复盘",{"type":17,"children":18,"toc":1025},"root",[19,60,65,78,84,89,102,285,328,334,355,381,390,403,408,420,742,769,796,804,809,838,843,848,867,896,958,977,990,998,1019],{"type":20,"tag":21,"props":22,"children":23},"element","p",{},[24,27,34,36,43,45,51,53,58],{"type":25,"value":26},"text","9 月 21 号恢复 pve2 的时候（经过在",{"type":20,"tag":28,"props":29,"children":31},"a",{"href":30},"\u002Fblog\u002F2026-09-22-pve2-power-key-boot-path\u002F",[32],{"type":25,"value":33},"这篇",{"type":25,"value":35},"），我在 mac 上跑了一次 ",{"type":20,"tag":37,"props":38,"children":40},"code",{"className":39},[],[41],{"type":25,"value":42},"cluster start all",{"type":25,"value":44},"。mac 上的 ",{"type":20,"tag":37,"props":46,"children":48},{"className":47},[],[49],{"type":25,"value":50},"cluster",{"type":25,"value":52}," 是个包装脚本，它把命令通过 ssh 透传给主节点（201）上的集群脚本，用法和在主节点上直接敲 ",{"type":20,"tag":37,"props":54,"children":56},{"className":55},[],[57],{"type":25,"value":50},{"type":25,"value":59}," 一样，输出也带颜色。start all 就是由主节点那边按 ZooKeeper、HDFS、YARN、Hive、Kafka、HBase 的顺序一路起下去。",{"type":20,"tag":21,"props":61,"children":62},{},[63],{"type":25,"value":64},"下面的经过是根据当时的提交记录和脚本整理的。",{"type":20,"tag":21,"props":66,"children":67},{},[68,70,76],{"type":25,"value":69},"start all 跑完 7 分钟后看 ",{"type":20,"tag":37,"props":71,"children":73},{"className":72},[],[74],{"type":25,"value":75},"cluster health",{"type":25,"value":77},"：YARN 异常；HBase 只剩 202 上的备用 HMaster 在顶着；Spark Thrift Server 的端口没了。同一时间，经 ssh 起到其他节点上的 DataNode、NodeManager、Kafka 全都活着。",{"type":20,"tag":79,"props":80,"children":82},"h2",{"id":81},"死掉的几个有什么共同点",[83],{"type":25,"value":81},{"type":20,"tag":21,"props":85,"children":86},{},[87],{"type":25,"value":88},"ResourceManager、HMaster、Spark Thrift Server，按当时的记录，这三个都是集群脚本在主节点本机直接拉起来的；活下来的那些，是从主节点再 ssh 到别的节点起的。差别就在是不是主节点本机的进程。",{"type":20,"tag":21,"props":90,"children":91},{},[92,94,100],{"type":25,"value":93},"再看 mac 上的包装脚本，透传用的是 ",{"type":20,"tag":37,"props":95,"children":97},{"className":96},[],[98],{"type":25,"value":99},"ssh -tt",{"type":25,"value":101},"：",{"type":20,"tag":103,"props":104,"children":108},"pre",{"className":105,"code":106,"language":107,"meta":7,"style":7},"language-bash shiki shiki-themes github-light github-dark","# 透传执行：保留终端颜色（-t 分配伪终端）\n# beeline 等交互式命令需要完整 PTY；非交互命令用 -tt 也可正常运行\n_run() {\n  ssh -tt -o ConnectTimeout=5 -o BatchMode=yes \\\n      \"${MASTER_USER}@${MASTER_HOST}\" \\\n      \"${REMOTE_CMD} $(printf '%q ' \"$@\")\" 2>\u002Fdev\u002Fnull\n}\n","bash",[109],{"type":20,"tag":37,"props":110,"children":111},{"__ignoreMap":7},[112,124,133,149,194,227,276],{"type":20,"tag":113,"props":114,"children":117},"span",{"class":115,"line":116},"line",1,[118],{"type":20,"tag":113,"props":119,"children":121},{"style":120},"--shiki-default:#6A737D;--shiki-dark:#6A737D",[122],{"type":25,"value":123},"# 透传执行：保留终端颜色（-t 分配伪终端）\n",{"type":20,"tag":113,"props":125,"children":127},{"class":115,"line":126},2,[128],{"type":20,"tag":113,"props":129,"children":130},{"style":120},[131],{"type":25,"value":132},"# beeline 等交互式命令需要完整 PTY；非交互命令用 -tt 也可正常运行\n",{"type":20,"tag":113,"props":134,"children":136},{"class":115,"line":135},3,[137,143],{"type":20,"tag":113,"props":138,"children":140},{"style":139},"--shiki-default:#6F42C1;--shiki-dark:#B392F0",[141],{"type":25,"value":142},"_run",{"type":20,"tag":113,"props":144,"children":146},{"style":145},"--shiki-default:#24292E;--shiki-dark:#E1E4E8",[147],{"type":25,"value":148},"() {\n",{"type":20,"tag":113,"props":150,"children":152},{"class":115,"line":151},4,[153,158,164,169,175,180,184,189],{"type":20,"tag":113,"props":154,"children":155},{"style":139},[156],{"type":25,"value":157},"  ssh",{"type":20,"tag":113,"props":159,"children":161},{"style":160},"--shiki-default:#005CC5;--shiki-dark:#79B8FF",[162],{"type":25,"value":163}," -tt",{"type":20,"tag":113,"props":165,"children":166},{"style":160},[167],{"type":25,"value":168}," -o",{"type":20,"tag":113,"props":170,"children":172},{"style":171},"--shiki-default:#032F62;--shiki-dark:#9ECBFF",[173],{"type":25,"value":174}," ConnectTimeout=",{"type":20,"tag":113,"props":176,"children":177},{"style":160},[178],{"type":25,"value":179},"5",{"type":20,"tag":113,"props":181,"children":182},{"style":160},[183],{"type":25,"value":168},{"type":20,"tag":113,"props":185,"children":186},{"style":171},[187],{"type":25,"value":188}," BatchMode=yes",{"type":20,"tag":113,"props":190,"children":191},{"style":160},[192],{"type":25,"value":193}," \\\n",{"type":20,"tag":113,"props":195,"children":197},{"class":115,"line":196},5,[198,203,208,213,218,223],{"type":20,"tag":113,"props":199,"children":200},{"style":171},[201],{"type":25,"value":202},"      \"${",{"type":20,"tag":113,"props":204,"children":205},{"style":145},[206],{"type":25,"value":207},"MASTER_USER",{"type":20,"tag":113,"props":209,"children":210},{"style":171},[211],{"type":25,"value":212},"}@${",{"type":20,"tag":113,"props":214,"children":215},{"style":145},[216],{"type":25,"value":217},"MASTER_HOST",{"type":20,"tag":113,"props":219,"children":220},{"style":171},[221],{"type":25,"value":222},"}\"",{"type":20,"tag":113,"props":224,"children":225},{"style":160},[226],{"type":25,"value":193},{"type":20,"tag":113,"props":228,"children":230},{"class":115,"line":229},6,[231,235,240,245,250,255,260,265,271],{"type":20,"tag":113,"props":232,"children":233},{"style":171},[234],{"type":25,"value":202},{"type":20,"tag":113,"props":236,"children":237},{"style":145},[238],{"type":25,"value":239},"REMOTE_CMD",{"type":20,"tag":113,"props":241,"children":242},{"style":171},[243],{"type":25,"value":244},"} $(",{"type":20,"tag":113,"props":246,"children":247},{"style":160},[248],{"type":25,"value":249},"printf",{"type":20,"tag":113,"props":251,"children":252},{"style":171},[253],{"type":25,"value":254}," '%q ' \"",{"type":20,"tag":113,"props":256,"children":257},{"style":160},[258],{"type":25,"value":259},"$@",{"type":20,"tag":113,"props":261,"children":262},{"style":171},[263],{"type":25,"value":264},"\")\"",{"type":20,"tag":113,"props":266,"children":268},{"style":267},"--shiki-default:#D73A49;--shiki-dark:#F97583",[269],{"type":25,"value":270}," 2>",{"type":20,"tag":113,"props":272,"children":273},{"style":171},[274],{"type":25,"value":275},"\u002Fdev\u002Fnull\n",{"type":20,"tag":113,"props":277,"children":279},{"class":115,"line":278},7,[280],{"type":20,"tag":113,"props":281,"children":282},{"style":145},[283],{"type":25,"value":284},"}\n",{"type":20,"tag":21,"props":286,"children":287},{},[288,290,296,298,304,306,312,314,319,321,326],{"type":25,"value":289},"当初加 ",{"type":20,"tag":37,"props":291,"children":293},{"className":292},[],[294],{"type":25,"value":295},"-tt",{"type":25,"value":297}," 是为了保留颜色，也为了让 beeline 这种交互命令能用。注释里还写着\"非交互命令用 -tt 也可正常运行\"，这次就栽在这句上。同一个脚本里检查 ssh 连通性的 ",{"type":20,"tag":37,"props":299,"children":301},{"className":300},[],[302],{"type":25,"value":303},"_check_ssh",{"type":25,"value":305}," 用的一直是 ",{"type":20,"tag":37,"props":307,"children":309},{"className":308},[],[310],{"type":25,"value":311},"ssh -n",{"type":25,"value":313},"，只有真正干活的 ",{"type":20,"tag":37,"props":315,"children":317},{"className":316},[],[318],{"type":25,"value":142},{"type":25,"value":320}," 用了 ",{"type":20,"tag":37,"props":322,"children":324},{"className":323},[],[325],{"type":25,"value":295},{"type":25,"value":327},"。",{"type":20,"tag":79,"props":329,"children":331},{"id":330},"tt-为什么会把进程带走",[332],{"type":25,"value":333},"-tt 为什么会把进程带走",{"type":20,"tag":21,"props":335,"children":336},{},[337,339,345,347,353],{"type":25,"value":338},"先说几个词。伪终端（PTY）是内核模拟出来的终端设备，sshd 用它让远端的程序以为自己连着一个真的终端，",{"type":20,"tag":37,"props":340,"children":342},{"className":341},[],[343],{"type":25,"value":344},"top",{"type":25,"value":346},"、",{"type":20,"tag":37,"props":348,"children":350},{"className":349},[],[351],{"type":25,"value":352},"vim",{"type":25,"value":354},"、beeline 这类交互程序离了它就没法正常用。一个终端会带着一个会话，会话里的进程又分成几个进程组，其中一个是前台进程组。SIGHUP 是\"挂断\"信号，名字来自当年终端连着的电话线挂断：终端没了，内核就用它通知还挂在这个终端上的进程，大多数程序收到以后默认直接退出。",{"type":20,"tag":21,"props":356,"children":357},{},[358,364,366,371,373,379],{"type":20,"tag":37,"props":359,"children":361},{"className":360},[],[362],{"type":25,"value":363},"ssh -t",{"type":25,"value":365}," 会在远端分配一个 PTY，",{"type":20,"tag":37,"props":367,"children":369},{"className":368},[],[370],{"type":25,"value":295},{"type":25,"value":372}," 是强制分配，哪怕本地没有终端也照样分配。远端命令就跑在以这个 PTY 为控制终端的会话里。会话结束、PTY 被销毁时，内核会给这个终端的前台进程组发 SIGHUP。非交互的 bash 不开作业控制，用 ",{"type":20,"tag":37,"props":374,"children":376},{"className":375},[],[377],{"type":25,"value":378},"&",{"type":25,"value":380}," 放到后台的进程还留在 shell 的进程组里，会一起收到。从主节点 ssh 到别的节点起的进程，属于另一台机器上的另一个会话，这个信号碰不到它们。当时的判断就是这样：主节点本机起的守护进程，跟着 ssh 会话的结束一起被带走了。",{"type":20,"tag":21,"props":382,"children":383},{},[384],{"type":20,"tag":385,"props":386,"children":389},"img",{"alt":387,"src":388},"ssh -tt 透传 cluster start all 时的进程关系。mac 上的包装脚本用 ssh -tt 连到主节点 201，远端分配的 PTY 是这个会话的控制终端，会话里是非交互 bash 和集群脚本，集群脚本在本机直接拉起的 ResourceManager、HBase HMaster、Spark Thrift Server 都标为没了。集群脚本再 ssh 到 202 到 207 去起的 DataNode、NodeManager、Kafka 全都活着，它们属于另一台机器的另一个会话。底部注明这是当时的判断，以及仓库里的脚本是从 201 再 ssh 回自己去起 Spark Thrift Server 的","\u002Fimages\u002Fblog\u002Fssh-sighup\u002Fprocess-session.svg",[],{"type":20,"tag":21,"props":391,"children":392},{},[393,395,401],{"type":25,"value":394},"这种事之前其实见过一回。9 月 4 号把 DolphinScheduler 迁到集群模式的时候（经过在",{"type":20,"tag":28,"props":396,"children":398},{"href":397},"\u002Fblog\u002F2026-09-06-gmall-dw-on-genesis\u002F",[399],{"type":25,"value":400},"电商数仓那篇",{"type":25,"value":402},"），Worker 用后台子 shell 并行启动，进程会随 ssh 退出被带走，当时只记了一条\"Worker 必须逐节点串行启动\"就绕过去了。两次都是进程的生命周期和 ssh 会话绑在了一起。",{"type":20,"tag":79,"props":404,"children":406},{"id":405},"怎么改的",[407],{"type":25,"value":405},{"type":20,"tag":21,"props":409,"children":410},{},[411,413,418],{"type":25,"value":412},"默认改成 ",{"type":20,"tag":37,"props":414,"children":416},{"className":415},[],[417],{"type":25,"value":311},{"type":25,"value":419},"，只有交互式的 beeline 才分配 PTY：",{"type":20,"tag":103,"props":421,"children":423},{"className":105,"code":422,"language":107,"meta":7,"style":7},"_needs_pty() {\n  case \"$1\" in\n    beeline) [ $# -eq 1 ] ;;   # `beeline check` 是非交互的，不需要 PTY\n    *)       return 1 ;;\n  esac\n}\n\n_run() {\n  local ssh_tty=\"-n\"\n  _needs_pty \"$@\" && ssh_tty=\"-tt\"\n  ssh $ssh_tty -o ConnectTimeout=5 -o BatchMode=yes \\\n      \"${MASTER_USER}@${MASTER_HOST}\" \\\n      \"${REMOTE_CMD} $(printf '%q ' \"$@\")\" 2>\u002Fdev\u002Fnull\n}\n",[424],{"type":20,"tag":37,"props":425,"children":426},{"__ignoreMap":7},[427,439,467,511,533,541,548,557,569,593,628,666,694,734],{"type":20,"tag":113,"props":428,"children":429},{"class":115,"line":116},[430,435],{"type":20,"tag":113,"props":431,"children":432},{"style":139},[433],{"type":25,"value":434},"_needs_pty",{"type":20,"tag":113,"props":436,"children":437},{"style":145},[438],{"type":25,"value":148},{"type":20,"tag":113,"props":440,"children":441},{"class":115,"line":126},[442,447,452,457,462],{"type":20,"tag":113,"props":443,"children":444},{"style":267},[445],{"type":25,"value":446},"  case",{"type":20,"tag":113,"props":448,"children":449},{"style":171},[450],{"type":25,"value":451}," \"",{"type":20,"tag":113,"props":453,"children":454},{"style":160},[455],{"type":25,"value":456},"$1",{"type":20,"tag":113,"props":458,"children":459},{"style":171},[460],{"type":25,"value":461},"\"",{"type":20,"tag":113,"props":463,"children":464},{"style":267},[465],{"type":25,"value":466}," in\n",{"type":20,"tag":113,"props":468,"children":469},{"class":115,"line":135},[470,476,481,486,491,496,501,506],{"type":20,"tag":113,"props":471,"children":473},{"style":472},"--shiki-default:#032F62;--shiki-dark:#DBEDFF",[474],{"type":25,"value":475},"    beeline",{"type":20,"tag":113,"props":477,"children":478},{"style":267},[479],{"type":25,"value":480},")",{"type":20,"tag":113,"props":482,"children":483},{"style":145},[484],{"type":25,"value":485}," [ ",{"type":20,"tag":113,"props":487,"children":488},{"style":160},[489],{"type":25,"value":490},"$#",{"type":20,"tag":113,"props":492,"children":493},{"style":267},[494],{"type":25,"value":495}," -eq",{"type":20,"tag":113,"props":497,"children":498},{"style":160},[499],{"type":25,"value":500}," 1",{"type":20,"tag":113,"props":502,"children":503},{"style":145},[504],{"type":25,"value":505}," ] ;;   ",{"type":20,"tag":113,"props":507,"children":508},{"style":120},[509],{"type":25,"value":510},"# `beeline check` 是非交互的，不需要 PTY\n",{"type":20,"tag":113,"props":512,"children":513},{"class":115,"line":151},[514,519,524,528],{"type":20,"tag":113,"props":515,"children":516},{"style":267},[517],{"type":25,"value":518},"    *)",{"type":20,"tag":113,"props":520,"children":521},{"style":267},[522],{"type":25,"value":523},"       return",{"type":20,"tag":113,"props":525,"children":526},{"style":160},[527],{"type":25,"value":500},{"type":20,"tag":113,"props":529,"children":530},{"style":145},[531],{"type":25,"value":532}," ;;\n",{"type":20,"tag":113,"props":534,"children":535},{"class":115,"line":196},[536],{"type":20,"tag":113,"props":537,"children":538},{"style":267},[539],{"type":25,"value":540},"  esac\n",{"type":20,"tag":113,"props":542,"children":543},{"class":115,"line":229},[544],{"type":20,"tag":113,"props":545,"children":546},{"style":145},[547],{"type":25,"value":284},{"type":20,"tag":113,"props":549,"children":550},{"class":115,"line":278},[551],{"type":20,"tag":113,"props":552,"children":554},{"emptyLinePlaceholder":553},true,[555],{"type":25,"value":556},"\n",{"type":20,"tag":113,"props":558,"children":560},{"class":115,"line":559},8,[561,565],{"type":20,"tag":113,"props":562,"children":563},{"style":139},[564],{"type":25,"value":142},{"type":20,"tag":113,"props":566,"children":567},{"style":145},[568],{"type":25,"value":148},{"type":20,"tag":113,"props":570,"children":572},{"class":115,"line":571},9,[573,578,583,588],{"type":20,"tag":113,"props":574,"children":575},{"style":267},[576],{"type":25,"value":577},"  local",{"type":20,"tag":113,"props":579,"children":580},{"style":145},[581],{"type":25,"value":582}," ssh_tty",{"type":20,"tag":113,"props":584,"children":585},{"style":267},[586],{"type":25,"value":587},"=",{"type":20,"tag":113,"props":589,"children":590},{"style":171},[591],{"type":25,"value":592},"\"-n\"\n",{"type":20,"tag":113,"props":594,"children":596},{"class":115,"line":595},10,[597,602,606,610,614,619,623],{"type":20,"tag":113,"props":598,"children":599},{"style":139},[600],{"type":25,"value":601},"  _needs_pty",{"type":20,"tag":113,"props":603,"children":604},{"style":171},[605],{"type":25,"value":451},{"type":20,"tag":113,"props":607,"children":608},{"style":160},[609],{"type":25,"value":259},{"type":20,"tag":113,"props":611,"children":612},{"style":171},[613],{"type":25,"value":461},{"type":20,"tag":113,"props":615,"children":616},{"style":145},[617],{"type":25,"value":618}," && ssh_tty",{"type":20,"tag":113,"props":620,"children":621},{"style":267},[622],{"type":25,"value":587},{"type":20,"tag":113,"props":624,"children":625},{"style":171},[626],{"type":25,"value":627},"\"-tt\"\n",{"type":20,"tag":113,"props":629,"children":631},{"class":115,"line":630},11,[632,636,641,646,650,654,658,662],{"type":20,"tag":113,"props":633,"children":634},{"style":139},[635],{"type":25,"value":157},{"type":20,"tag":113,"props":637,"children":638},{"style":145},[639],{"type":25,"value":640}," $ssh_tty ",{"type":20,"tag":113,"props":642,"children":643},{"style":160},[644],{"type":25,"value":645},"-o",{"type":20,"tag":113,"props":647,"children":648},{"style":171},[649],{"type":25,"value":174},{"type":20,"tag":113,"props":651,"children":652},{"style":160},[653],{"type":25,"value":179},{"type":20,"tag":113,"props":655,"children":656},{"style":160},[657],{"type":25,"value":168},{"type":20,"tag":113,"props":659,"children":660},{"style":171},[661],{"type":25,"value":188},{"type":20,"tag":113,"props":663,"children":664},{"style":160},[665],{"type":25,"value":193},{"type":20,"tag":113,"props":667,"children":669},{"class":115,"line":668},12,[670,674,678,682,686,690],{"type":20,"tag":113,"props":671,"children":672},{"style":171},[673],{"type":25,"value":202},{"type":20,"tag":113,"props":675,"children":676},{"style":145},[677],{"type":25,"value":207},{"type":20,"tag":113,"props":679,"children":680},{"style":171},[681],{"type":25,"value":212},{"type":20,"tag":113,"props":683,"children":684},{"style":145},[685],{"type":25,"value":217},{"type":20,"tag":113,"props":687,"children":688},{"style":171},[689],{"type":25,"value":222},{"type":20,"tag":113,"props":691,"children":692},{"style":160},[693],{"type":25,"value":193},{"type":20,"tag":113,"props":695,"children":697},{"class":115,"line":696},13,[698,702,706,710,714,718,722,726,730],{"type":20,"tag":113,"props":699,"children":700},{"style":171},[701],{"type":25,"value":202},{"type":20,"tag":113,"props":703,"children":704},{"style":145},[705],{"type":25,"value":239},{"type":20,"tag":113,"props":707,"children":708},{"style":171},[709],{"type":25,"value":244},{"type":20,"tag":113,"props":711,"children":712},{"style":160},[713],{"type":25,"value":249},{"type":20,"tag":113,"props":715,"children":716},{"style":171},[717],{"type":25,"value":254},{"type":20,"tag":113,"props":719,"children":720},{"style":160},[721],{"type":25,"value":259},{"type":20,"tag":113,"props":723,"children":724},{"style":171},[725],{"type":25,"value":264},{"type":20,"tag":113,"props":727,"children":728},{"style":267},[729],{"type":25,"value":270},{"type":20,"tag":113,"props":731,"children":732},{"style":171},[733],{"type":25,"value":275},{"type":20,"tag":113,"props":735,"children":737},{"class":115,"line":736},14,[738],{"type":20,"tag":113,"props":739,"children":740},{"style":145},[741],{"type":25,"value":284},{"type":20,"tag":21,"props":743,"children":744},{},[745,751,753,759,761,767],{"type":20,"tag":37,"props":746,"children":748},{"className":747},[],[749],{"type":25,"value":750},"-n",{"type":25,"value":752}," 把 stdin 接到 \u002Fdev\u002Fnull。带了远端命令又没加 ",{"type":20,"tag":37,"props":754,"children":756},{"className":755},[],[757],{"type":25,"value":758},"-t",{"type":25,"value":760},"，ssh 就不会分配 PTY。",{"type":20,"tag":37,"props":762,"children":764},{"className":763},[],[765],{"type":25,"value":766},"beeline check",{"type":25,"value":768}," 这种带子命令的调用是非交互的，也不给 PTY。",{"type":20,"tag":21,"props":770,"children":771},{},[772,774,779,781,787,789,794],{"type":25,"value":773},"改之前确认了一下颜色会不会丢。不少命令行工具发现输出不是终端，就会自动关掉颜色，当初加 ",{"type":20,"tag":37,"props":775,"children":777},{"className":776},[],[778],{"type":25,"value":758},{"type":25,"value":780}," 也是怕这个。这个集群脚本不一样，颜色是写死的 ANSI 转义，",{"type":20,"tag":37,"props":782,"children":784},{"className":783},[],[785],{"type":25,"value":786},"RED='\\033[0;31m'",{"type":25,"value":788}," 这种变量，不检测输出是不是终端，所以 ",{"type":20,"tag":37,"props":790,"children":792},{"className":791},[],[793],{"type":25,"value":750},{"type":25,"value":795}," 下颜色照样在。",{"type":20,"tag":21,"props":797,"children":798},{},[799],{"type":20,"tag":385,"props":800,"children":803},{"alt":801,"src":802},"ssh -tt 和 ssh -n 的对比表。远端终端：-tt 强制分配 PTY，本地没终端也分配；-n 不分配。stdin：-tt 接本地输入；-n 接到 \u002Fdev\u002Fnull。会话结束时：-tt 销毁 PTY，内核给前台进程组发 SIGHUP；-n 没有控制终端，也就没有这次挂断信号。颜色：两者都有，因为脚本里的 ANSI 转义是写死的。现在谁用：-tt 只给不带子命令的 beeline，-n 用于其余所有命令包括 beeline check。底部补充 nohup 起的进程会忽略 SIGHUP","\u002Fimages\u002Fblog\u002Fssh-sighup\u002Ftt-vs-n.svg",[],{"type":20,"tag":79,"props":805,"children":807},{"id":806},"怎么验证的",[808],{"type":25,"value":806},{"type":20,"tag":21,"props":810,"children":811},{},[812,814,820,822,828,830,836],{"type":25,"value":813},"改完做了三项检查。",{"type":20,"tag":37,"props":815,"children":817},{"className":816},[],[818],{"type":25,"value":819},"bash -n",{"type":25,"value":821}," 语法检查通过。经包装脚本跑 ",{"type":20,"tag":37,"props":823,"children":825},{"className":824},[],[826],{"type":25,"value":827},"cluster restart spk",{"type":25,"value":829},"，包装脚本退出 15 秒后，Spark HistoryServer 的进程和端口都还在。",{"type":20,"tag":37,"props":831,"children":833},{"className":832},[],[834],{"type":25,"value":835},"cluster status zk",{"type":25,"value":837}," 的原始输出字节里，ANSI 转义序列都还在。",{"type":20,"tag":79,"props":839,"children":841},{"id":840},"还没解释透的地方",[842],{"type":25,"value":840},{"type":20,"tag":21,"props":844,"children":845},{},[846],{"type":25,"value":847},"这个解释到现在也没完全坐实，有几处对不上。",{"type":20,"tag":21,"props":849,"children":850},{},[851,853,858,860,865],{"type":25,"value":852},"上面的验证只说明改成 ",{"type":20,"tag":37,"props":854,"children":856},{"className":855},[],[857],{"type":25,"value":750},{"type":25,"value":859}," 以后，服务在包装脚本退出后还活着。反过来用 ",{"type":20,"tag":37,"props":861,"children":863},{"className":862},[],[864],{"type":25,"value":295},{"type":25,"value":866}," 起一遍、看着进程被带走的对照实验，记录里没有。因果是从\"死的都是本机进程\"这个规律推出来的，没有复现过。",{"type":20,"tag":21,"props":868,"children":869},{},[870,872,878,880,886,888,894],{"type":25,"value":871},"再就是 nohup。Spark 的 ",{"type":20,"tag":37,"props":873,"children":875},{"className":874},[],[876],{"type":25,"value":877},"start-history-server.sh",{"type":25,"value":879}," 和 ",{"type":20,"tag":37,"props":881,"children":883},{"className":882},[],[884],{"type":25,"value":885},"start-thriftserver.sh",{"type":25,"value":887}," 都是转调 ",{"type":20,"tag":37,"props":889,"children":891},{"className":890},[],[892],{"type":25,"value":893},"spark-daemon.sh",{"type":25,"value":895},"，它是这样起进程的：",{"type":20,"tag":103,"props":897,"children":899},{"className":105,"code":898,"language":107,"meta":7,"style":7},"nohup -- \"$@\" >> $log 2>&1 \u003C \u002Fdev\u002Fnull &\n",[900],{"type":20,"tag":37,"props":901,"children":902},{"__ignoreMap":7},[903],{"type":20,"tag":113,"props":904,"children":905},{"class":115,"line":116},[906,911,916,920,924,928,933,938,943,948,953],{"type":20,"tag":113,"props":907,"children":908},{"style":139},[909],{"type":25,"value":910},"nohup",{"type":20,"tag":113,"props":912,"children":913},{"style":160},[914],{"type":25,"value":915}," --",{"type":20,"tag":113,"props":917,"children":918},{"style":171},[919],{"type":25,"value":451},{"type":20,"tag":113,"props":921,"children":922},{"style":160},[923],{"type":25,"value":259},{"type":20,"tag":113,"props":925,"children":926},{"style":171},[927],{"type":25,"value":461},{"type":20,"tag":113,"props":929,"children":930},{"style":267},[931],{"type":25,"value":932}," >>",{"type":20,"tag":113,"props":934,"children":935},{"style":145},[936],{"type":25,"value":937}," $log ",{"type":20,"tag":113,"props":939,"children":940},{"style":267},[941],{"type":25,"value":942},"2>&1",{"type":20,"tag":113,"props":944,"children":945},{"style":267},[946],{"type":25,"value":947}," \u003C",{"type":20,"tag":113,"props":949,"children":950},{"style":171},[951],{"type":25,"value":952}," \u002Fdev\u002Fnull",{"type":20,"tag":113,"props":954,"children":955},{"style":145},[956],{"type":25,"value":957}," &\n",{"type":20,"tag":21,"props":959,"children":960},{},[961,963,968,970,975],{"type":25,"value":962},"nohup 的作用就是让进程忽略 SIGHUP。这样一来，拿来验证的 Spark HistoryServer 本身就带着 nohup，就算还用 ",{"type":20,"tag":37,"props":964,"children":966},{"className":965},[],[967],{"type":25,"value":295},{"type":25,"value":969},"，它多半也能活下来，所以那次验证证明不了 ",{"type":20,"tag":37,"props":971,"children":973},{"className":972},[],[974],{"type":25,"value":295},{"type":25,"value":976}," 就是元凶。",{"type":20,"tag":21,"props":978,"children":979},{},[980,982,988],{"type":25,"value":981},"而且仓库里留的那份集群脚本里，Spark Thrift Server 是从主节点再 ssh 回它自己去起的，本来就不在那个 PTY 会话里（主节点上实际跑的版本要是和仓库里一样的话）。照这么看，SIGHUP 解释不了 Spark Thrift Server 为什么没了。它是以 YARN client 模式跑的，一种可能是 ResourceManager 先倒了，它跟着退出，但这也只是推测。HMaster 是集群脚本在主节点上调 ",{"type":20,"tag":37,"props":983,"children":985},{"className":984},[],[986],{"type":25,"value":987},"start-hbase.sh",{"type":25,"value":989}," 起的，符合本机进程这个特征，可它退出的直接原因同样没看到。",{"type":20,"tag":21,"props":991,"children":992},{},[993],{"type":20,"tag":385,"props":994,"children":997},{"alt":995,"src":996},"ssh -tt 这个解释的证据。撑得住的四条：死掉的三个都是主节点本机拉起的、活着的都是 ssh 到别的节点起的；改成 -n 后跑 cluster restart spk，包装脚本退出 15 秒后 HistoryServer 进程和端口都在；cluster status zk 的原始输出里 ANSI 转义都在；9 月 4 号 DS Worker 用后台子 shell 并行起也被带走过。对不上或欠着的四条：没做过用 -tt 的反向对照；HistoryServer 本身由 nohup 起；仓库脚本里 Spark Thrift Server 是 ssh 回 201 起的；HMaster 退出的直接原因没看到。底部是还差的两步：翻退出前的日志，以及下次起集群时跑 ps -o pid,pgid,sid,tty,cmd -C java","\u002Fimages\u002Fblog\u002Fssh-sighup\u002Fevidence.svg",[],{"type":20,"tag":21,"props":999,"children":1000},{},[1001,1003,1009,1011,1017],{"type":25,"value":1002},"要坐实，得把那次 ResourceManager、HMaster、Spark Thrift Server 退出前的日志翻出来，看它们到底是收到 SIGHUP 退的，还是别的原因。下次起集群，也可以先用 ",{"type":20,"tag":37,"props":1004,"children":1006},{"className":1005},[],[1007],{"type":25,"value":1008},"ps -o pid,pgid,sid,tty,cmd -C java",{"type":25,"value":1010}," 看一眼这几个 Java 进程挂在哪个会话上，TTY 那一栏要是 ",{"type":20,"tag":37,"props":1012,"children":1014},{"className":1013},[],[1015],{"type":25,"value":1016},"pts\u002FN",{"type":25,"value":1018},"，说明它还挂在某个终端上。这两步记录里都没有，算是欠着的。",{"type":20,"tag":1020,"props":1021,"children":1022},"style",{},[1023],{"type":25,"value":1024},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":7,"searchDepth":135,"depth":135,"links":1026},[1027,1028,1029,1030,1031],{"id":81,"depth":126,"text":81},{"id":330,"depth":126,"text":333},{"id":405,"depth":126,"text":405},{"id":806,"depth":126,"text":806},{"id":840,"depth":126,"text":840},"markdown","content:blog:2026-09-26-ssh-tty-sighup-daemons.md","content","blog\u002F2026-09-26-ssh-tty-sighup-daemons.md","blog\u002F2026-09-26-ssh-tty-sighup-daemons","md",[1039,1042],{"_path":1040,"title":1041},"\u002Fblog\u002F2026-09-28-homelab-production-deployment","家里这套生产环境：几台机器各跑什么，和踩坑以后定下的几条规矩",{"_path":1043,"title":1044},"\u002Fblog\u002F2026-09-24-argus-cost-eats-returns","回测毛收益 +27%，扣完成本变成 -20%",1796523532784]