【问题标题】:How can I run gradle apps in background in Gitlab job (nohup is not working in gitlab)如何在 Gitlab 作业中在后台运行 gradle 应用程序(nohup 在 gitlab 中不起作用)
【发布时间】:2022-08-03 00:31:48
【问题描述】:

我想运行几个 gradle 应用程序,它们将作为后台进程运行大约 5 分钟(调用 gradle 应用程序后将运行更多命令,然后作业将完成)。他们使用 nohup 在我的 ubuntu 机器上执行得很好:

nohup gradle app1 > nohup1.out 2>&1 &
nohup gradle app2 > nohup2.out 2>&1 &
...

运行这些命令不需要按中断按钮或回车,因此我可以在后台连续运行多个 gradle 应用程序并开始与它们交互。

虽然今天我了解到 Gitlab runner 取消了所有子进程,因此 nohup 在 Gitlab CI 工作中毫无用处。

是否有解决方法,以便我可以在后台运行 Gitlab 作业中的多个 gradle 作业? 我尝试使用工具但它并没有带来功能诺哈普做过。

  • making nohup useless in a Gitlab CI job. nohup 在 gitalb ci 作业中没用,因为没有终端发送 HUP 信号,而不是因为进程组被杀死。 I can run multiple gradle jobs inside Gitlab job in the background?“gradle jobs”的目的是什么?你在执行吗应用部署?您使用的是哪个 gitlab 执行器?你不能用org.gradle.parallel=true 运行gradle app1 app2 吗?
  • @KamilCuk 我启动了多个 gradle 应用程序,以便下一步我可以对其功能进行测试。我不确定执行人的问题。我创建了一个 Dockerfile 并设置了一个带有各种库的 gitlab 容器 ubuntu 映像,然后我将这些库提供给 Gitlab 运行器。

标签: bash gitlab gitlab-ci gitlab-ci-runner nohup


【解决方案1】:

要后台作业,您不需要使用nohup,您可以简单地在命令末尾使用& 来“后台”它。

举个简单的例子:

test_job:
  image: python:3.9-slim
  script:
    - python -m http.server  & # Start a server on port 8000 in the background
    - apt update && apt install -y curl
    - echo "contacting background server..."
    - curl http://localhost:8000

这有效。运行最后一个script: 步骤后,该作业将退出(也关闭后台作业)。

在尝试访问它们之前,请确保为您的应用程序提供足够的启动时间。

【讨论】:

    猜你喜欢
    • 2018-01-07
    • 2021-05-23
    • 1970-01-01
    • 2022-01-14
    • 1970-01-01
    • 2022-01-04
    • 2021-01-20
    • 2021-03-08
    • 2019-05-22
    相关资源
    最近更新 更多