Launchd OSX does not work bash with teamcity agent

I have a script startup.sh shell that does the following (create a RAM disk and run 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 

I can run this from the command line by typing ./startup.sh and it works correctly. When I start from start, it ONLY creates a RAM disk, teamcity does not start.

My starting layer is 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> 

What am I missing?

EDIT

Here is the agent.sh file:

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

+6
source share
1 answer

Your .sh script agent starts the teamcity agent in the background and then shuts down. This contradicts the starting way of managing tasks - launchdd expects that his jobs will work in the foreground, where he will be able to control them, restart them if they are broken, close them if necessary, etc. Basically, everything you do with a PID file is what usually works for you. In this case, the direct problem is that when one of the started tasks exits (which you do almost immediately after it runs the command in the background), startd clears any remaining mess, including killing any lost subprocess, for example, an agent teamcity.

You have two options:

  • Go to the starting method of doing something. This would mean replacing agent.sh script with one that performs functions such as checking prerequisites, searching for Java, etc., and then starting the groupcity agent in the foreground. In fact, it is probably best if the agent is an exec agent, so the agent runs directly as a child of launchd, rather than a child of the shell (which is a child of the launch); this gives you the launch of a more direct connection to monitor and manage it.
  • Reporting the launch is not to kill abandoned subprocesses by adding <key>AbandonProcessGroup</key><true/> to .plist. This is simpler, but you choose from all the other launchd management features.
+3
source

Source: https://habr.com/ru/post/1013360/


All Articles