Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RunFd #526

Closed
wants to merge 2 commits into from
Closed

Add RunFd #526

wants to merge 2 commits into from

Conversation

yyoshiki41
Copy link
Contributor

I use gin http.Server under circus which is a socket manager.
I need to run http.Server through a file descriptor, so implemented RunFd method.

When using other socket managers (e.g. einhorn), maybe work well.

Usage

package main

import (
    "flag"
    "github.com/yyoshiki41/gin"
)

var (
    fd = flag.Int("fd", -1, "")
)

func main() {
    flag.Parse()

    r := gin.Default()
    // Ping test
    r.GET("/ping", func(c *gin.Context) {
        c.String(200, "pong")
    })
    // Method arg is the file descriptor number(int).
    r.RunFd(*fd)
}

and, circus.ini example is below.

[circus]
statsd = 1

[watcher:webapp]
cmd = ./main -fd $(circus.sockets.web)
numprocesses = 1
use_sockets = True

[socket:web]
host = 127.0.0.1
port = 8080

Demo

$ circusd circus.ini
2016-02-03 11:07:13 circus[46347] [INFO] Starting master on pid 46347
2016-02-03 11:07:13 circus[46347] [INFO] sockets started
2016-02-03 11:07:13 circus[46347] [INFO] Arbiter now waiting for commands
2016-02-03 11:07:13 circus[46347] [INFO] webapp started
2016-02-03 11:07:13 circus[46347] [INFO] circusd-stats started
[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
 - using env:   export GIN_MODE=release
 - using code:  gin.SetMode(gin.ReleaseMode)

[GIN-debug] GET    /ping                     --> main.main.func1 (3 handlers)
[GIN-debug] Listening and serving HTTP on fd@5
2016-02-03 11:07:13 circus[46354] [INFO] Starting the stats streamer
# Ping test
$ curl localhost:8080/ping
pong

# Other terminal
[GIN] 2016/02/03 - 11:08:11 | 200 |    2.571629ms | 127.0.0.1 |   GET     /ping

thx ☀️

Review on Reviewable

@gotokatsuya
Copy link

+1

@manucorporat

@se77en
Copy link
Contributor

se77en commented Feb 14, 2016

+1
@yyoshiki41 Hope you can write the tests.

@coveralls
Copy link

coveralls commented May 4, 2016

Coverage Status

Coverage decreased (-0.6%) to 93.445% when pulling d277f9d on yyoshiki41:listen-fd into 542be2f on gin-gonic:develop.

@yyoshiki41
Copy link
Contributor Author

@manucorporat @se77en
sorry for late reply.

Added the tests for RunFd.
plz, review this pr.

@coveralls
Copy link

coveralls commented May 4, 2016

Coverage Status

Coverage increased (+0.04%) to 94.125% when pulling 48a0ff6 on yyoshiki41:listen-fd into 542be2f on gin-gonic:develop.

@coveralls
Copy link

coveralls commented Jul 1, 2016

Coverage Status

Coverage increased (+0.04%) to 94.125% when pulling f26b613 on yyoshiki41:listen-fd into f931d1e on gin-gonic:develop.

@thinkerou
Copy link
Member

@yyoshiki41 please re-commit the pull request to master branch, thanks!

@yyoshiki41
Copy link
Contributor Author

@thinkerou

thanks for your reply.
Close this and reopened a new pr forked master.
#1609

thanks.

@yyoshiki41 yyoshiki41 closed this Oct 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants