TeamCity iPhone Build Agent occasionally needs to be restarted
===

After juggling permissions issues and setup issues and build script issues I FINALLY got TeamCity to build my iPhone app and publish ad_hoc builds to TestFlight.

This is the script from Jonah that I used as my base.
http://blog.carbonfive.com/2011/05/04/automated-ad-hoc-builds-using-xcode-4/

After a long weekend I came in to work to find my build agent was no longer working.

    [10:40:03][Step 1/2] Starting: /Library/TeamCity/buildAgent/temp/agentTmp/custom_script7798470032061763046
    [10:40:03][Step 1/2] in directory: /Library/TeamCity/buildAgent/work/9891710001721542
    [10:40:03][Step 1/2] **** Validate Keychain
    [10:40:03][Step 1/2] Available provisioning profiles
    [10:40:03][Step 1/2] 0 valid identities found

I checked the server and the identities are still there.

    1) ***** "iPhone Developer: James Ashworth (*****)"
    2) ***** "iPhone Distribution: ***MY COMPANY***"

If I restart the build agent manually.

    sudo launchctl unload /Library/LaunchDaemons/jetbrains.teamcity.BuildAgent.plist
    sudo launchctl load /Library/LaunchDaemons/jetbrains.teamcity.BuildAgent.plist

Then it magically starts working again.

    [11:29:08][Step 1/2] Starting: /Library/TeamCity/buildAgent/temp/agentTmp/custom_script6220287408011621917
    [11:29:08][Step 1/2] in directory: /Library/TeamCity/buildAgent/work/9891710001721542
    [11:29:08][Step 1/2] **** Validate Keychain
    [11:29:09][Step 1/2] Available provisioning profiles
    [11:29:09][Step 1/2]   1) ***** "iPhone Developer: James Ashworth (*****)"
    [11:29:09][Step 1/2]   2) ***** "iPhone Distribution: ***MY COMPANY***"
    [11:29:09][Step 1/2]      2 valid identities found

I'm sure the machine was restarted and the launchdaemon was unable to reacquire the provisioning profiles.  But doesn't the machine just run the same commands I ran to restart the launchdaemon at boot up?

I'm sure it's a permissions issue, I just have NO idea what is configured incorrectly.