From a10e80842fc3ee1fa361a6421ac3404b2e3c50aa Mon Sep 17 00:00:00 2001 From: kataras Date: Tue, 13 Jun 2017 09:06:10 +0300 Subject: [PATCH] Update to 7.1.1. Read HISTORY.md Fix https://github.com/iris-contrib/community-board/issues/11 Read the latest fixes and features by visiting: https://github.com/kataras/iris/blob/master/HISTORY.md Former-commit-id: 7f35481f917673d0bbb356a4816d9cf54cc0c9ba --- HISTORY.md | 5 ++ README.md | 4 +- _examples/README.md | 1 + .../graceful-shutdown/basic/main.go | 4 +- .../graceful-shutdown/custom-host/main.go | 2 +- .../graceful-shutdown/custom-notifier/main.go | 48 +++++++++++++++++++ core/host/supervisor.go | 12 ++++- iris.go | 2 +- 8 files changed, 71 insertions(+), 7 deletions(-) create mode 100644 _examples/intermediate/graceful-shutdown/custom-notifier/main.go diff --git a/HISTORY.md b/HISTORY.md index d4c2d21f..8a062d86 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -29,6 +29,11 @@ Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.co The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please! + +# Tu, 13 June 2017 | v7.1.1 + +Fix [that](https://github.com/iris-contrib/community-board/issues/11). + # Mo, 12 June 2017 | v7.1.0 Fix [that](https://github.com/iris-contrib/community-board/issues/10). diff --git a/README.md b/README.md index 609d9a64..fc2a7de1 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ A fast, cross-platform and efficient web framework with robust set of well-desig [![Report card](https://img.shields.io/badge/report%20card%20-a%2B-F44336.svg?style=flat-square)](http://goreportcard.com/report/kataras/iris) [![Support forum](https://img.shields.io/badge/support-page-ec2eb4.svg?style=flat-square)](http://support.iris-go.com) [![Examples](https://img.shields.io/badge/howto-examples-3362c2.svg?style=flat-square)](https://github.com/kataras/iris/tree/master/_examples#table-of-contents) -[![Godocs](https://img.shields.io/badge/7.1.0-%20documentation-5272B4.svg?style=flat-square)](https://godoc.org/github.com/kataras/iris) +[![Godocs](https://img.shields.io/badge/7.1.1-%20documentation-5272B4.svg?style=flat-square)](https://godoc.org/github.com/kataras/iris) [![Chat](https://img.shields.io/badge/community-%20chat-00BCD4.svg?style=flat-square)](https://kataras.rocket.chat/channel/iris) [![Buy me a cup of coffee](https://img.shields.io/badge/support-%20open--source-F4A460.svg?logo=data:image%2Fsvg%2Bxml%3Bbase64%2CPHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDAwIDEwMDAiPjxwYXRoIGZpbGw9InJnYigyMjAsMjIwLDIyMCkiIGQ9Ik04ODYuNiwzMDUuM2MtNDUuNywyMDMuMS0xODcsMzEwLjMtNDA5LjYsMzEwLjNoLTc0LjFsLTUxLjUsMzI2LjloLTYybC0zLjIsMjEuMWMtMi4xLDE0LDguNiwyNi40LDIyLjYsMjYuNGgxNTguNWMxOC44LDAsMzQuNy0xMy42LDM3LjctMzIuMmwxLjUtOGwyOS45LTE4OS4zbDEuOS0xMC4zYzIuOS0xOC42LDE4LjktMzIuMiwzNy43LTMyLjJoMjMuNWMxNTMuNSwwLDI3My43LTYyLjQsMzA4LjktMjQyLjdDOTIxLjYsNDA2LjgsOTE2LjcsMzQ4LjYsODg2LjYsMzA1LjN6Ii8%2BPHBhdGggZmlsbD0icmdiKDIyMCwyMjAsMjIwKSIgZD0iTTc5MS45LDgzLjlDNzQ2LjUsMzIuMiw2NjQuNCwxMCw1NTkuNSwxMEgyNTVjLTIxLjQsMC0zOS44LDE1LjUtNDMuMSwzNi44TDg1LDg1MWMtMi41LDE1LjksOS44LDMwLjIsMjUuOCwzMC4ySDI5OWw0Ny4zLTI5OS42bC0xLjUsOS40YzMuMi0yMS4zLDIxLjQtMzYuOCw0Mi45LTM2LjhINDc3YzE3NS41LDAsMzEzLTcxLjIsMzUzLjItMjc3LjVjMS4yLTYuMSwyLjMtMTIuMSwzLjEtMTcuOEM4NDUuMSwxODIuOCw4MzMuMiwxMzAuOCw3OTEuOSw4My45TDc5MS45LDgzLjl6Ii8%2BPC9zdmc%2B)](https://github.com/kataras/iris#buy-me-a-cup-of-coffee) @@ -409,7 +409,7 @@ Besides the fact that we have a [community chat][Chat] for questions or reports Version ------------ -Current: **7.1.0** +Current: **7.1.1** Each new release is pushed to the master. It stays there until the next version. When a next version is released then the previous version goes to its own branch with `gopkg.in` as its import path (and its own vendor folder), in order to keep it working "for-ever". diff --git a/_examples/README.md b/_examples/README.md index 2293b1e6..0275b5c0 100644 --- a/_examples/README.md +++ b/_examples/README.md @@ -58,6 +58,7 @@ It doesn't contains "best ways" neither explains all its features. It's just a s * [Graceful Shutdown](intermediate/graceful-shutdown) * [Basic and simple](intermediate/graceful-shutdown/basic/main.go) * [Custom Host](intermediate/graceful-shutdown/custom-host/main.go) + * [Custom notifier](intermediate/graceful-shutdown/custom-notifier/main.go) * [Custom HTTP Server](intermediate/custom-httpserver) * [Iris way](intermediate/custom-httpserver/iris-way/main.go) * [Standar way](intermediate/custom-httpserver/std-way/main.go) diff --git a/_examples/intermediate/graceful-shutdown/basic/main.go b/_examples/intermediate/graceful-shutdown/basic/main.go index 75c97c2a..94f1385d 100644 --- a/_examples/intermediate/graceful-shutdown/basic/main.go +++ b/_examples/intermediate/graceful-shutdown/basic/main.go @@ -12,7 +12,7 @@ import ( // Before continue, please read the below notes: // // Current version of Iris is auto-graceful on control+C/command+C -// or whenever host's .Shutdown called. +// or kill command sent or whenever app.Shutdown called. // // In order to add a custom interrupt handler(ctrl+c/cmd+c) or // shutdown manually you have to "schedule a host supervisor's task" or @@ -29,7 +29,7 @@ func main() { // tasks are always running in their go-routine by-default. // - // register custom interrupt handler, fires when ctrl+C/cmd+C pressed. + // register custom interrupt handler, fires when ctrl+C/cmd+C pressed or kill command sent. app.Scheduler.Schedule(host.OnInterrupt(func(proc host.TaskProcess) { println("Shutdown the server gracefully...") diff --git a/_examples/intermediate/graceful-shutdown/custom-host/main.go b/_examples/intermediate/graceful-shutdown/custom-host/main.go index e5c11e0d..5c0fde64 100644 --- a/_examples/intermediate/graceful-shutdown/custom-host/main.go +++ b/_examples/intermediate/graceful-shutdown/custom-host/main.go @@ -33,7 +33,7 @@ func main() { // tasks are always running in their go-routine by-default. // - // register custom interrupt handler, fires when ctrl+C/cmd+C pressed, as we did before. + // register custom interrupt handler, fires when ctrl+C/cmd+C pressed or kill command sent, as we did before. srv.Schedule(host.OnInterrupt(func(proc host.TaskProcess) { println("Shutdown the server gracefully...") diff --git a/_examples/intermediate/graceful-shutdown/custom-notifier/main.go b/_examples/intermediate/graceful-shutdown/custom-notifier/main.go new file mode 100644 index 00000000..ac6b6d90 --- /dev/null +++ b/_examples/intermediate/graceful-shutdown/custom-notifier/main.go @@ -0,0 +1,48 @@ +package main + +import ( + stdContext "context" + "os" + "os/signal" + "syscall" + "time" + + "github.com/kataras/iris" + "github.com/kataras/iris/context" +) + +func main() { + app := iris.New() + // output startup banner and error logs on os.Stdout + + app.Get("/", func(ctx context.Context) { + ctx.HTML("

hi, I just exist in order to see if the server is closed

") + }) + + go func() { + ch := make(chan os.Signal, 1) + signal.Notify(ch, + // kill -SIGINT XXXX or Ctrl+c + os.Interrupt, + syscall.SIGINT, // register that too, it should be ok + // os.Kill is equivalent with the syscall.Kill + os.Kill, + syscall.SIGKILL, // register that too, it should be ok + // kill -SIGTERM XXXX + syscall.SIGTERM, + ) + select { + case <-ch: + println("Shutdown the server gracefully...") + + timeout := 5 * time.Second // give the server 5 seconds to wait for idle connections. + ctx, cancel := stdContext.WithTimeout(stdContext.Background(), timeout) + defer cancel() + app.Shutdown(ctx) + } + }() + + // Start the server and disable the default interrupt handler in order to handle it clear and simple by our own, without + // any issues. + app.Run(iris.Addr(":8080"), iris.WithoutInterruptHandler) +} diff --git a/core/host/supervisor.go b/core/host/supervisor.go index 517fbbcc..da22258f 100644 --- a/core/host/supervisor.go +++ b/core/host/supervisor.go @@ -13,6 +13,7 @@ import ( "os/signal" "sync" "sync/atomic" + "syscall" "github.com/kataras/iris/core/errors" "github.com/kataras/iris/core/nettools" @@ -138,7 +139,16 @@ func (su *Supervisor) supervise(blockFunc func() error) error { // we do it here. These tasks are canceled already too. go func() { ch := make(chan os.Signal, 1) - signal.Notify(ch, os.Interrupt, os.Kill) + signal.Notify(ch, + // kill -SIGINT XXXX or Ctrl+c + os.Interrupt, + syscall.SIGINT, // register that too, it should be ok + // os.Kill is equivalent with the syscall.SIGKILL + os.Kill, + syscall.SIGKILL, // register that too, it should be ok + // kill -SIGTERM XXXX + syscall.SIGTERM, + ) select { case <-ch: su.Scheduler.runOnInterrupt(host) diff --git a/iris.go b/iris.go index 88fcbc8a..49ac6b9c 100644 --- a/iris.go +++ b/iris.go @@ -41,7 +41,7 @@ const ( // Version is the current version number of the Iris Web framework. // // Look https://github.com/kataras/iris#where-can-i-find-older-versions for older versions. - Version = "7.1.0" + Version = "7.1.1" ) const (