Read environment variables from a file in launchd?

Rainer Müller raimue at macports.org
Mon Jul 17 20:00:21 UTC 2023


On 17/07/2023 20.58, Zhenfu Shi wrote:
> I’m looking for a way to import environment variables for a process started by launchd. systemd on Linux has EnvironmentFile key which allows env vars to be read from a file, can launchd do something similar?
> I’m asking this because my cloudflared port has command line options hardcoded into its launchd script which gets overwritten on every upgrade. If I can somehow make those options read in from another file I can make them configuable to the users.

Unfortunately, I do not think this is easily possible with launchd.

The only solution I can think of would be to wrap it with a shell script. Or use an external start script that reads the arguments from a file.

<key>ProgramArguments</key>
<array>
    <string>/bin/sh</string>
    <string>-c</string>
    <string>source /opt/local/etc/foo/options && exec /opt/local/bin/foo $FOO_OPTIONS</string>
</array>


Rainer


More information about the macports-dev mailing list