Skip to content
This repository has been archived by the owner on Jun 10, 2018. It is now read-only.

Setting up launch_socket_server with nginx #1

Closed
josh opened this issue Dec 9, 2014 · 1 comment
Closed

Setting up launch_socket_server with nginx #1

josh opened this issue Dec 9, 2014 · 1 comment

Comments

@josh
Copy link

josh commented Dec 9, 2014

Hey @sstephenson,

Mostly just wanted to share an experience setting up nginx under launch_socket_server. Not really an issue, you can close this thread whenever.

First off I wanted to create a basic homebrew formula for launch_socket_server. I ran into some bizarre make install issue that only occurred in the homebrew build environment.

$ brew install launch_socket_server.rb
==> Downloading https://github.com/sstephenson/launch_socket_server/archive/v1.0
Already downloaded: /Library/Caches/Homebrew/launch_socket_server-1.0.0.tar.gz
==> make install

GOPATH=/private/tmp/launch_socket_server-zUBBM9/launch_socket_server-1.0.0 go build -o sbin/launch_socket_server src/launch_socket_server.go
# launch
cannot load DWARF output from $WORK/launch/_obj//_cgo_.o: decoding dwarf section info at offset 0x0: too short
make: *** [sbin/launch_socket_server] Error 2

I ended up having to call go build directly. https://github.com/josh/homebrew-github/blob/master/launch_socket_server.rb I couldn't figure out why. Maybe it had something to do with the $PWD or $GOPATH in that ENV.

I was hoping you could get this on homebrew officially someday.

Moving along to using the stock nginx from brew install nginx. I ended up with the following launchd plist.

<?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>
    <key>Label</key>
    <string>homebrew.mxcl.nginx</string>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <true/>
    <key>UserName</key>
    <string>josh</string>
    <key>GroupName</key>
    <string>staff</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/local/sbin/launch_socket_server</string>
        <string>/usr/local/bin/nginx</string>
        <string>-g</string>
        <string>daemon off;</string>
    </array>
    <key>WorkingDirectory</key>
    <string>/usr/local</string>
    <key>EnvironmentVariables</key>
    <dict>
      <key>LAUNCH_PROGRAM_TCP_ADDRESS</key>
      <string>127.0.0.1:8080</string>
    </dict>
    <key>Sockets</key>
    <dict>
        <key>Socket</key>
        <dict>
            <key>SockNodeName</key>
            <string>0.0.0.0</string>
            <key>SockServiceName</key>
            <string>80</string>
        </dict>
    </dict>
  </dict>
</plist>

Then I had to make sure to update the listen port to 8080 in the nginx.conf.

It was nice having nginx running as my own user and so could reload the config without sudo.

I was annoyed to find out there was no way to use environment variables in nginx.conf. I was hoping listen $LAUNCH_PROGRAM_TCP_ADDRESS would work.

I also tried to get unix sockets working to avoid hogging an internal port. I wasn't able to get that working either, its probably because I wasn't unlinking the socket before nginx started. I guess I would want to write a bash script wrapper that unlinked the socket and exec'd nginx.

Thanks!

@josh josh closed this as completed Dec 20, 2014
@MikeMcQuaid
Copy link

In case it's of interest: the Homebrew formula for this now installs a plist to do this for e.g. nginx by default now: Homebrew/homebrew-core#2773

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants