grace

package module
v0.0.0-...-3d1d697 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 9, 2022 License: MIT Imports: 11 Imported by: 1

README

Grace

Build Status

Fiber Prefork 模式下的优雅退出

⚙ Installation

go get -u github.com/eininst/fiber-prefork-grace

⚡ Quickstart

package main

import (
    grace "github.com/eininst/fiber-prefork-grace"
    "github.com/gofiber/fiber/v2"
    "time"
)

func main() {
    app := fiber.New(fiber.Config{
        Prefork:     true,
        ReadTimeout: time.Second * 5,
    })

    grace.Listen(app, ":8080")
}

Default listen signal: TERM

kill -term pid
[GRACE] 2022/09/08 06:29:37 Child pid 35951 Shotdown
[GRACE] 2022/09/08 06:29:37 Child pid 35953 Shotdown
[GRACE] 2022/09/08 06:29:37 Child pid 35948 Shotdown
[GRACE] 2022/09/08 06:29:37 Child pid 35946 Shotdown
[GRACE] 2022/09/08 06:29:37 Child pid 35949 Shotdown
[GRACE] 2022/09/08 06:29:37 Child pid 35952 Shotdown
[GRACE] 2022/09/08 06:29:37 Child pid 35950 Shotdown
[GRACE] 2022/09/08 06:29:37 Child pid 35947 Shotdown
[GRACE] 2022/09/08 06:29:37 Main  pid 35945 Shotdown

You can customize it all you want:

grace.Listen(app, ":8080", grace.Config{
    Timeout: time.Second * 15,
    Signal:  syscall.SIGTERM,
})

See examples

License

MIT

Documentation

Index

Constants

View Source
const FIBER_CHILD_LOCK_FILE = "/tmp/fiber_child.lock"

Variables

View Source
var DefaultConfig = Config{
	Signal:  syscall.SIGTERM,
	Timeout: time.Second * 10,
}

Functions

func Listen

func Listen(app *fiber.App, addr string, config ...Config)

func ListenTLS

func ListenTLS(app *fiber.App, addr string, certFile, keyFile string, config ...Config)

Types

type Config

type Config struct {
	Signal  os.Signal
	Timeout time.Duration
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL