github - 自托管 Github 运行器 : start a background server process in a job and let it run after the job ends

标签 github github-actions

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

  • 在自托管运行器中,运行服务器进程。使用 curl 调用它。此进程在执行下一个“另一个作业”期间监视某些内容
  • 运行“另一项工作”(不在自托管运行器上)
  • 在Self-hosted runner中,再次调用curl进行统计。

我的 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...

根据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

但是在“完成作业”下的操作日志中:

Cleaning up orphan processes
Terminate orphan process: pid (4731) (npm)
Terminate orphan process: pid (4742) (node)

所以当我还有一步的时候

  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

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

问题:我如何在第一份工作中启动一个在工作结束后保持运行的流程?

最佳答案

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

运行:RUNNER_TRACKING_ID=""&& (nohup npm start&)

已找到此建议 in this thread on GitHub.

关于github - 自托管 Github 运行器 : start a background server process in a job and let it run after the job ends,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68439803/

相关文章:

Github Wiki - 源代码语法高亮

git - 来自私有(private) GitHub 存储库的 Cordova 插件

git - 在 Git 中跟踪待办事项和问题

python - Github Actions 一直卡在某个任务上,最终因超时而失败

关于拉取请求和主分支的 Github 操作

github-api - 是否可以通过 GitHub API 找出问题是否已通过拉取请求关闭

automated-tests - 在 Github 操作上运行的机器人框架无法获取测试返回代码

github - 使用 Vlad 通过 SSH 部署

jenkins - 如何更新 PR 合并提交的构建状态

将文件从一个存储库复制到另一个存储库的 github 操作