Self-Hosted Github Runner:在作业中启动一个后台服务器进程并让它在作业结束后运行

Ask*_*mov 8 github github-actions

我正在尝试执行以下操作:

  • 在自托管运行器中,运行服务器进程。使用curl 调用它。该进程在执行下一个“另一个作业”期间监视某些内容
  • 运行“另一项作业”(不在自托管运行器上)
  • 在自托管运行器中,再次调用curl来收集统计信息。

jobs我的 Github Actions 工作流程中有以下内容:

start-process:  # THIS JOB IS SUPPOSED TO START A SERVER IN BACKGROUND
    name: Start
    needs: start-runner # previous job starts the runner
    runs-on: ${{ needs.start-runner.outputs.label }} # run the job on the newly created runner
    steps:
      - uses: actions/checkout@v2
      - name: npm install
        working-directory: ./monitor
        run: npm install
      - name: npm start
        run: nohup npm start & # this starts the server in background
        working-directory: ./monitor
      - run: curl http://localhost:8080/start
      - run: ps aux


anotherjob:
  // perform another job...
Run Code Online (Sandbox Code Playgroud)

根据ps aux我的服务器进程:

root      4746  4.8  1.2 721308 48396 ?        Sl   11:20   0:00 npm
root      4757 85.8  4.9 736308 196788 ?       Sl   11:20   0:04 node /actions-runner/_work/<myrepo>/<myrepo>/monitor/node_modules/.bin/ts-node src/main.ts
root      4773  0.0  0.0 124052  2924 ?        S    11:20   0:00 /usr/bin/bash -e /actions-runner/_work/_temp/51a508d8-9c2c-4723-9691-3252c8d53d88.sh
Run Code Online (Sandbox Code Playgroud)

但在操作日志中,我在“完成作业”下有:

Cleaning up orphan processes
Terminate orphan process: pid (4731) (npm)
Terminate orphan process: pid (4742) (node)
Run Code Online (Sandbox Code Playgroud)

所以当我再迈出一步时

  statistic:
    name: Output Statistics
    needs:
      - start-runner
      - start-process
      - anotherjob
    runs-on: ${{ needs.start-runner.outputs.label }}  
 
    steps:
      - run: ps aux
      - run: curl http://localhost:8080/statistics

Run Code Online (Sandbox Code Playgroud)

这失败了:ps aux不再有进程并且curl无法连接到该地址。

问题:如何在第一个作业中启动一个在作业结束后仍保持运行状态的进程?

Ask*_*mov 3

事实证明,为了“保护”进程免遭清理,它可以运行为

run: RUNNER_TRACKING_ID="" && (nohup npm start&)

这个建议是在 GitHub 上的这个线程中找到的。