How do I detect that I'm running as a LaunchAgent under launchd on Mac OS X?
This is for a program (written in Go) that needs to restart when told to do so. If it's been started from a terminal or init script, it needs to do this by itself. If running under a service manager it should not attempt to restart but simply exit and be restarted by the manager.
For example, when running under Solaris SMF the environment variable SMF_FMRI
is set, but I see nothing similar in launchd.
There are obvious workarounds (require a command line flag to be used or an environment variable to be set) but I'm interested in an "automatic" solution.
(This is not a duplicate of the similar sounding question How to check if launchd has started the script?)