Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sword-jin/go-graceful
a golang package for restart your application graceful, support with supervisor, systemd
https://github.com/sword-jin/go-graceful
fasthttp gin golang golang-package graceful http iris zero-time
Last synced: about 2 months ago
JSON representation
a golang package for restart your application graceful, support with supervisor, systemd
- Host: GitHub
- URL: https://github.com/sword-jin/go-graceful
- Owner: sword-jin
- License: apache-2.0
- Created: 2020-02-27T12:55:24.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-02-28T10:24:22.000Z (almost 5 years ago)
- Last Synced: 2024-10-15T07:04:36.844Z (2 months ago)
- Topics: fasthttp, gin, golang, golang-package, graceful, http, iris, zero-time
- Language: Go
- Size: 1.5 MB
- Stars: 17
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-graceful
[![Go Report Card](https://goreportcard.com/badge/github.com/rrylee/go-graceful)](https://goreportcard.com/report/github.com/rrylee/go-graceful)
Inspired by [graceful](https://github.com/kuangchanglang/graceful) and [overseer](https://github.com/jpillora/overseer), for support some framework.
\>= go1.8
### Feature
* multi service, port
* worker with framework
* support supervisor, systemd
* connection limit![](./image/process.png)
use master-worker model because supervisor should keep master pid.
### Example
std http server
```go
type myHandler struct{}
func (*myHandler) ServeHTTP(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte(fmt.Sprintf("Hello world, pid = %d, ppid=%d", syscall.Getpid(), syscall.Getppid())))
}func main() {
mux := http.NewServeMux()
mux.Handle("/", &myHandler{})srv := &http.Server{Handler: mux}
grace := graceful.New()
grace.RegisterService(graceful.NewAddress("127.0.0.1:8124", "tcp"), func(ln net.Listener) error {
return srv.Serve(ln)
}, func() error {
return srv.Shutdown(context.Background())
})grace.Run()
err := grace.Run()
if err != nil {
log.Fatal(err)
}
}
```default reload signals syscall.SIGHUP, syscall.SIGUSR1, syscall.SIGUSR2
so `crul 127.0.0.1:8124`
```bash
$ Hello world, pid = 13435, ppid=13434$ kill -USR1 13434
$ curl 127.0.0.1:8124
Hello world, pid = 13479, ppid=13434
```use iris
```go
app := iris.New()app.Get("/", func(c context2.Context) {
_, _ = c.Writef("hello world! pid=%d, ppid=%d", syscall.Getpid(), syscall.Getppid())
})grace := graceful.New()
grace.RegisterService(graceful.NewAddress("127.0.0.1:8124", "tcp"), func(ln net.Listener) error {
return app.Run(iris.Listener(ln))
}, func() error {
return app.Shutdown(context.Background())
})
err := grace.Run()
if err != nil {
log.Fatal(err)
}
```alse fasthttp example and other framework.