humanmade / Cavalcade-Runner

Daemon for Cavalcade, a scalable WordPress jobs system.
https://engineering.hmn.md/projects/cavalcade/
53 stars 26 forks source link

Mac OS launchctl config #49

Open JPry opened 6 years ago

JPry commented 6 years ago

This isn't so much an issue as something that I wanted to share for the benefit of others.

I set up Cavalcade for a local site (which is powered by Valet+), and I wanted to have Cavalcade automatically launch using the native Mac OS launchctl system.

Here's the config file I ended up using, with specifics replaced:

<?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>
        <!-- This label should be unique to the site -->
        <key>Label</key>
        <string>some-site.cavalcade</string>

        <key>ProgramArguments</key>
        <array>
                <string>bash</string>
                <string>-lc</string>
                <!-- Update the cavalcade location as needed -->
                <!-- Replace /path/to/wp/site with the correct path -->
                <string>~/projects/Cavalcade-Runner/bin/cavalcade /path/to/wp/site</string>
        </array>

        <key>RunAtLoad</key>
        <true/>

        <!-- These log file paths are used with Homebrew, but I've mapped Cavalcade here too -->
        <key>StandardOutPath</key>
        <string>/usr/local/var/log/cavalcade.log</string>

        <key>StandardErrorPath</key>
        <string>/usr/local/var/log/cavalcade_error.log</string>
</dict>
</plist>

This file is placed into my ~/Library/LaunchAgents/ directory with a .plist extension. For consistency, I've matched the file name with the Label some-site.cavalcade above. To load get this running, I then do this:

launchctl load -w ~/Library/LaunchAgents/some-site.cavalcade.plist
rmccue commented 6 years ago

@JPry Thanks for this! Since we already have systemd and upstart config in the repo, do you want to PR this up?

JPry commented 6 years ago

@rmccue I'd be glad to submit a PR. I just a have a few questions before I do, since the specifics might need to change.

  1. What should I use as the default path for cavalcade? I see in systemd.service it's set to /etc/cavalcade/bin/cavalcade. On a Mac when using Homebrew, something like /usr/local/bin/cavalcade would be expected.
  2. What should I use as the default path for the site root? Running a local setup on a Mac is obviously a bit different than a server setup. I follow Valet's recommendation to put my local sites into ~/Sites/, and each project has its own folder there.

One note here as well, is that I'm essentially telling launchctl to run the following command:

bash -lc ~/projects/Cavalcade-Runner/bin/cavalcade /path/to/wp/site

I've done it this way make it the same as a user manually running it from their login shell using the terminal, which includes relevant PATH settings. If anyone else has any additional expertise with running the launchctl process without emulating bash, I'd love more information on how to do that.

rmccue commented 6 years ago

@JPry Pick whatever you think is best for the defaults, and include a comment header (if possible) to note how to change them. :) As it's only an example config, no need to worry too much about it I think.