samuong / alpaca

A local HTTP proxy for command-line tools. Supports PAC scripts and NTLM authentication.
Apache License 2.0
184 stars 31 forks source link

Provide a Brew tap #55

Closed orj closed 4 years ago

orj commented 4 years ago

It would be super useful for alpaca to have a brew tap so it can be easily installed and updated without go installed.

samuong commented 4 years ago

I just created https://github.com/samuong/homebrew-alpaca, and you should now be able to do:

brew tap samuong/alpaca
brew install samuong/alpaca/alpaca

Let me know what you think?

samuong commented 4 years ago

Also I've added a launchd job definition, so that you can do brew services start alpaca.

However I'm not sure how to set StandardErrorPath and StandardOutPath to a value in the user's home directory (looks like launchd doesn't support globs like ~ or environment variables like $HOME), so I've just set both of these to /dev/null. This isn't ideal, so if you've got any tips on how to get this to work, it'd be much appreciated :)

This is all tested on Catalina 10.15.5.

camscale commented 4 years ago

My launchd config for alpaca that uses env vars:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>com.samoung.alpaca</string>
    <key>EnvironmentVariables</key>
    <dict>
        <key>PAC_URL</key>
        <string>http://example.com/proxy.pac</string>
    </dict>
    <key>ProgramArguments</key>
    <array>
     <string>sh</string>
     <string>-c</string>
     <string>exec $HOME/src/go/bin/alpaca -C $PAC_URL >>$HOME/Library/Logs/alpaca.log 2>&1</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <true/>
    <key>SoftResourceLimits</key>
    <dict>
      <key>NumberOfFiles</key>
      <integer>2048</integer>
    </dict>
  </dict>
</plist>
camh- commented 4 years ago

This does not have any sort of log rotation so it is not ideal. Not sure how that is meant to be managed on Macs.

samuong commented 4 years ago

Nice, thanks Cam! I'll do the sh -c thing in the formula, and the file limit is a good idea too.

As for log rotation, I'm not sure either. If we're not rotating logs, maybe > is better than >>?

camh- commented 4 years ago

The problem with > is that if it is crash-looping, you lose the logs each time it restarts and they may contain the info you need to stop it crash-looping. Maybe launchd stops running it after some number of crashes?

Also, is the plist installed per-user or system-wide? For alpaca it would want to be per-user, so $HOME should work. But if it is system-wide, $HOME probably wont be set. But logs should also go to the system log dir anyway.

samuong commented 4 years ago

Fair point re crash looping. Given the issues, I might just leave it as /dev/null, but if anyone wants to improve this, pull requests are welcome :)