• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

gracedemo/H18-Feb-2017-

gracehttp/H18-Feb-2017-

gracenet/H18-Feb-2017-

.travis.ymlH A D18-Feb-2017317

licenseH A D18-Feb-20171.5 KiB

patentsH A D18-Feb-20171.9 KiB

readme.mdH A D18-Feb-20172 KiB

readme.md

1grace [![Build Status](https://secure.travis-ci.org/facebookgo/grace.png)](https://travis-ci.org/facebookgo/grace)
2=====
3
4Package grace provides a library that makes it easy to build socket
5based servers that can be gracefully terminated & restarted (that is,
6without dropping any connections).
7
8It provides a convenient API for HTTP servers including support for TLS,
9especially if you need to listen on multiple ports (for example a secondary
10internal only admin server).  Additionally it is implemented using the same API
11as systemd providing [socket
12activation](http://0pointer.de/blog/projects/socket-activation.html)
13compatibility to also provide lazy activation of the server.
14
15
16Usage
17-----
18
19Demo HTTP Server with graceful termination and restart:
20https://github.com/facebookgo/grace/blob/master/gracedemo/demo.go
21
221. Install the demo application
23
24        go get github.com/facebookgo/grace/gracedemo
25
261. Start it in the first terminal
27
28        gracedemo
29
30   This will output something like:
31
32        2013/03/25 19:07:33 Serving [::]:48567, [::]:48568, [::]:48569 with pid 14642.
33
341. In a second terminal start a slow HTTP request
35
36        curl 'http://localhost:48567/sleep/?duration=20s'
37
381. In a third terminal trigger a graceful server restart (using the pid from your output):
39
40        kill -USR2 14642
41
421. Trigger another shorter request that finishes before the earlier request:
43
44        curl 'http://localhost:48567/sleep/?duration=0s'
45
46
47If done quickly enough, this shows the second quick request will be served by
48the new process (as indicated by the PID) while the slow first request will be
49served by the first server. It shows how the active connection was gracefully
50served before the server was shutdown. It is also showing that at one point
51both the new as well as the old server was running at the same time.
52
53
54Documentation
55-------------
56
57`http.Server` graceful termination and restart:
58https://godoc.org/github.com/facebookgo/grace/gracehttp
59
60`net.Listener` graceful termination and restart:
61https://godoc.org/github.com/facebookgo/grace/gracenet
62