启动的OSX无法与teamcity代理一起运行bash [英] Launchd OSX not running bash with teamcity agent

查看:67
本文介绍了启动的OSX无法与teamcity代理一起运行bash的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个执行以下操作的shell脚本 startup.sh (创建RAM磁盘并启动teamcity代理):

I have a shell script startup.sh that does the following (create a RAM disk and start the teamcity agent):

#!/bin/bash

DISK=`/usr/bin/hdiutil attach -nobrowse -nomount ram://16777216`

/usr/sbin/diskutil erasevolume HFS+ "RamDiskCache" $DISK

/Users/administrator/buildAgent/bin/agent.sh start

我可以在命令行中输入 ./startup.sh 来运行它,并且它可以正常运行.当我从启动状态运行时,它仅创建RAM磁盘,teamcity无法启动.

I can run this from the command line by typing ./startup.sh and it runs correctly. When I run from launchd, it ONLY creates the RAM disk, teamcity doesn't start.

我启动的plist位于〜/Library/LaunchAgents

My launchd plist is located in ~/Library/LaunchAgents

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>Label</key>
        <string>com.datafinch.teamcity</string>
        <key>Program</key>
        <string>/Users/administrator/startup.sh</string>
        <key>RunAtLoad</key>
        <true/>
    </dict>
</plist>

我想念什么?

编辑

这是agent.sh文件:

Here is the agent.sh file:

https://gist.github.com/chriskooken/19f5856e3ce3c2322c53cb0afa69b057

推荐答案

您的agent.sh脚本在后台启动teamcity代理,然后退出.这与已发布的管理作业方式相反–已启动预计其作业将在前台运行,可以监视它们,在崩溃时将其重新启动,在适当的时候将其关闭等.基本上,您要做的所有事情通常会为您处理PID文件.在这种情况下,直接的问题是,当launchd的作业之一退出(在后台运行teamcity后,您的工作几乎立即执行)时,launchd将清除所有剩余的混乱,包括杀死任何孤立的子进程,例如,例如,teamcity代理商.

Your agent.sh script launches the teamcity agent in the background, and then exits. This is contrary to the launchd way of managing jobs -- launchd expects its jobs to run in the foreground, where it can monitor them, restart them if they crash, shut them down when appropriate, etc. Basically, all the stuff you're doing with a PID file is what launchd normally takes care of for you. In this case, the direct problem is that when one of launchd's jobs exits (which yours does almost immediately, after it runs teamcity in the background), launchd will clean up any leftover mess, including killing any orphaned subprocess, like, say, the teamcity agent.

您有两种选择:

  • 转换为已发布的服务方式.这意味着将agent.sh脚本替换为执行诸如检查先决条件,查找Java等操作,然后在前台运行teamcity代理 的脚本.实际上,最好是 exec 作为代理,因此代理直接作为launchd的子代而不是shell的子代(shell的子代)运行;这样可以启动更直接的连接来监视和管理它.
  • 通过向.plist中添加< key> AbandonProcessGroup</key>< true/> ,Tell发起了不杀死放弃的子流程的任务.这比较简单,但是会让您退出已启动的所有其他管理功能.
  • Convert to the launchd way of doing things. This'll mean replacing the agent.sh script with one that does things like checking prerequisites, finding Java, etc and then runs the teamcity agent in the foreground. Actually, it's probably best if it execs the agent, so the agent runs directly as a child of launchd, rather than a child of the shell (which is a child of launchd); this gives launchd a more direct connection to monitor and manage it.
  • Tell launchd not to kill off abandoned subprocesses by adding <key>AbandonProcessGroup</key><true/> to the .plist. This is simpler, but opts you out of all of launchd's other management features.

这篇关于启动的OSX无法与teamcity代理一起运行bash的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆