【问题标题】:Self-Hosted Github Runner: start a background server process in a job and let it run after the job endsSelf-Hosted Github Runner:在作业中启动一个后台服务器进程,让它在作业结束后运行
【发布时间】:2021-09-27 01:50:03
【问题描述】:

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

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

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

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 无法连接到该地址。

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

【问题讨论】:

    标签: github github-actions


    【解决方案1】:

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

    run: RUNNER_TRACKING_ID="" &amp;&amp; (nohup npm start&amp;).

    这个建议被发现in this thread on GitHub.

    【讨论】:

      猜你喜欢
      • 2016-12-05
      • 1970-01-01
      • 2019-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-03
      • 2015-04-04
      • 1970-01-01
      相关资源
      最近更新 更多