Heroku support #7

Closed
jtarchie opened this Issue Jan 29, 2012 · 5 comments

Comments

Projects
None yet
2 participants
@jtarchie

I've wanted to use ngx_openresty for awhile, but didn't want to have to support a server, compilation, etc. Heroku is my goto. Their buildpack mechanism allows you to package the necessary binaries with your application code, so that it can be deployed to their cloud environment easily.

I work a with cloud hosting solutions. Heroku has proven, thus far, to be the most open and supportive environment for any platform that can serve HTTP requests.

I put together a proof of concept buildpack for Heroku that supports ngx_openresty. Basically any application that has a nginx.conf at the application's root level will automatically be packaged as an OpenResty application. I've compiled OpenResty of have every single module (no MySQL, since Heroku uses Postgres).

The buildpack can be found here. Right now its supporting an earlier version (1.0.10.24) of ngx_openresty, but with a little work could be expanded. Also, please keep in mind that I am currently hosting the buildpack, so my S3 charges are being applied, so keep it minimal.

Any questions or thoughts are welcome. Thanks for the great platform.

@agentzh

This comment has been minimized.

Show comment Hide comment
@agentzh

agentzh Jan 30, 2012

Member

Nice work! If there's anything that we can do to help you, please don't hesitate to let us know ;)

Thanks!

Member

agentzh commented Jan 30, 2012

Nice work! If there's anything that we can do to help you, please don't hesitate to let us know ;)

Thanks!

@jtarchie

This comment has been minimized.

Show comment Hide comment
@jtarchie

jtarchie Apr 23, 2012

There is something that I am trying to get to work. Heroku requires that logs be displayed to STDOUT while the process is running. For example when Rails is running, it writes the log directly to STDOUT. Nginx automatically prints to a file. Is there any to just redirect the log output STDOUT?

There is something that I am trying to get to work. Heroku requires that logs be displayed to STDOUT while the process is running. For example when Rails is running, it writes the log directly to STDOUT. Nginx automatically prints to a file. Is there any to just redirect the log output STDOUT?

@agentzh

This comment has been minimized.

Show comment Hide comment
@agentzh

agentzh Apr 23, 2012

Member

On Mon, Apr 23, 2012 at 9:58 AM, JT Archie
reply@reply.github.com
wrote:

There is something that I am trying to get to work. Heroku requires that logs be displayed to STDOUT while the process is running. For example when Rails is running, it writes the log directly to STDOUT. Nginx automatically prints to a file. Is there any to just redirect the log output STDOUT?

Yes, just use /dev/stdout as the error log file name:

error_log  /dev/stdout notice;

Also, it makes sense to disable daemon mode in nginx:

daemon off;

Regards,
-agentzh

Member

agentzh commented Apr 23, 2012

On Mon, Apr 23, 2012 at 9:58 AM, JT Archie
reply@reply.github.com
wrote:

There is something that I am trying to get to work. Heroku requires that logs be displayed to STDOUT while the process is running. For example when Rails is running, it writes the log directly to STDOUT. Nginx automatically prints to a file. Is there any to just redirect the log output STDOUT?

Yes, just use /dev/stdout as the error log file name:

error_log  /dev/stdout notice;

Also, it makes sense to disable daemon mode in nginx:

daemon off;

Regards,
-agentzh

@jtarchie jtarchie closed this May 31, 2012

@jtarchie

This comment has been minimized.

Show comment Hide comment
@jtarchie

jtarchie Jul 22, 2013

The above solution does not work. Heroku does not provide permission to /dev/stdout. I have been trying to figure out alternatives of /dev/stdout. I am currently trying to see if there is a way to do with fifo, but I am not holding my breath.

The above solution does not work. Heroku does not provide permission to /dev/stdout. I have been trying to figure out alternatives of /dev/stdout. I am currently trying to see if there is a way to do with fifo, but I am not holding my breath.

@jtarchie

This comment has been minimized.

Show comment Hide comment
@jtarchie

jtarchie Oct 13, 2013

The solution I've found, and recommended by Heroku is to tail the logs while the nginx runs in the background.

The startup script looks like this

#!/bin/sh
DEFAULT_CONF=nginx.conf
DEFAULT_ROOT="$(pwd)"

CONF="${1:-$DEFAULT_CONF}"
ROOT="${2:-$DEFAULT_ROOT}"

OUT_CONF="$CONF.compiled"
(
    mkdir -p logs
    touch logs/access.log logs/error.log
    #Redirect NGINX logs to stdout.
    echo 'buildpack=nginx at=logs-initialized'
    tail -qF -n 0 logs/*.log
    echo 'logs' >$psmgr
) &


(
    cd "$ROOT"
    cat "$CONF" | compile_nginx_config.lua > "$OUT_CONF"
    LD_LIBRARY_PATH="/app/packages/lib" nginx -p "$(pwd)" -c "$OUT_CONF"
)

I don't like it. Since heroku doesn't give us access to /dev/stdout are there any alternatives you can think of. Can we actually just have nginx stream it to standard out buffer?

The solution I've found, and recommended by Heroku is to tail the logs while the nginx runs in the background.

The startup script looks like this

#!/bin/sh
DEFAULT_CONF=nginx.conf
DEFAULT_ROOT="$(pwd)"

CONF="${1:-$DEFAULT_CONF}"
ROOT="${2:-$DEFAULT_ROOT}"

OUT_CONF="$CONF.compiled"
(
    mkdir -p logs
    touch logs/access.log logs/error.log
    #Redirect NGINX logs to stdout.
    echo 'buildpack=nginx at=logs-initialized'
    tail -qF -n 0 logs/*.log
    echo 'logs' >$psmgr
) &


(
    cd "$ROOT"
    cat "$CONF" | compile_nginx_config.lua > "$OUT_CONF"
    LD_LIBRARY_PATH="/app/packages/lib" nginx -p "$(pwd)" -c "$OUT_CONF"
)

I don't like it. Since heroku doesn't give us access to /dev/stdout are there any alternatives you can think of. Can we actually just have nginx stream it to standard out buffer?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment