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: 8 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 (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-02-28T10:24:22.000Z (over 6 years ago)
- Last Synced: 2025-04-12T10:12:33.162Z (about 1 year ago)
- Topics: fasthttp, gin, golang, golang-package, graceful, http, iris, zero-time
- Language: Go
- Size: 1.5 MB
- Stars: 17
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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

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.