├── .travis.yml ├── .gitignore ├── README.md ├── wrapper.go ├── demo └── main.go ├── continuous.go └── LICENSE /.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | go: 3 | - 1.11 4 | script: go get github.com/shafreeck/continuous 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | 8 | # Test binary, build with `go test -c` 9 | *.test 10 | 11 | # Output of the go coverage tool, specifically when used with LiteIDE 12 | *.out 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Continuous 2 | 3 | [![Build Status](https://travis-ci.org/distributedio/continuous.svg?branch=master)](https://travis-ci.org/distributedio/continuous) 4 | 5 | Continuous is a framework to upgrade a daemon binary without interrupt 6 | 7 | # Features 8 | * Emigrate listen fds 9 | * Flexible controlling on multiple phases 10 | * Graceful stop or force stop the old service 11 | * Rollback to the old service 12 | 13 | # Demo 14 | 15 | [source code](./demo/main.go) 16 | 17 | # TODO 18 | - [ ] Add unittests 19 | -------------------------------------------------------------------------------- /wrapper.go: -------------------------------------------------------------------------------- 1 | package continuous 2 | 3 | import ( 4 | "context" 5 | "net" 6 | "net/http" 7 | "time" 8 | 9 | "google.golang.org/grpc" 10 | ) 11 | 12 | type httpServer struct { 13 | *http.Server 14 | } 15 | 16 | func (s *httpServer) Stop() error { 17 | return s.Server.Close() 18 | } 19 | func (s *httpServer) GracefulStop() error { 20 | ctx, cancel := context.WithTimeout(context.Background(), time.Second) 21 | defer cancel() 22 | return s.Server.Shutdown(ctx) 23 | } 24 | 25 | func WrapHTTPServer(s *http.Server) Continuous { 26 | return &httpServer{s} 27 | } 28 | 29 | type httpServerTLS struct { 30 | *httpServer 31 | certFile string 32 | keyFile string 33 | } 34 | 35 | func WrapHTTPServerTLS(s *http.Server, certFile, keyFile string) Continuous { 36 | return &httpServerTLS{httpServer: &httpServer{s}, certFile: certFile, keyFile: keyFile} 37 | } 38 | func (s *httpServerTLS) Serve(lis net.Listener) error { 39 | return s.ServeTLS(lis, s.certFile, s.keyFile) 40 | } 41 | 42 | type grpcServer struct { 43 | *grpc.Server 44 | } 45 | 46 | func (s *grpcServer) Stop() error { 47 | s.Server.Stop() 48 | return nil 49 | } 50 | func (s *grpcServer) GracefulStop() error { 51 | s.Server.GracefulStop() 52 | return nil 53 | } 54 | 55 | func WrapGRPCServer(s *grpc.Server) Continuous { 56 | return &grpcServer{s} 57 | } 58 | -------------------------------------------------------------------------------- /demo/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "net/http" 7 | 8 | "github.com/distributedio/continuous" 9 | "google.golang.org/grpc" 10 | pb "google.golang.org/grpc/examples/helloworld/helloworld" 11 | ) 12 | 13 | // httpServer implements the Continuous interface 14 | type httpServer struct { 15 | *http.Server 16 | } 17 | 18 | func (hs *httpServer) Stop() error { 19 | return hs.Close() 20 | } 21 | func (hs *httpServer) GracefulStop() error { 22 | return hs.Shutdown(context.Background()) 23 | } 24 | 25 | // http handler 26 | type httpd struct{} 27 | 28 | func (h *httpd) ServeHTTP(w http.ResponseWriter, r *http.Request) { 29 | w.WriteHeader(200) 30 | w.Write([]byte("You got me!")) 31 | } 32 | 33 | // grpcServer implements the Continuous interface 34 | type grpcServer struct { 35 | *grpc.Server 36 | } 37 | 38 | func (gs *grpcServer) Stop() error { 39 | gs.Server.Stop() 40 | return nil 41 | } 42 | func (gs *grpcServer) GracefulStop() error { 43 | gs.Server.GracefulStop() 44 | return nil 45 | } 46 | 47 | // grpc handler 48 | type helloServer struct{} 49 | 50 | func (hs *helloServer) SayHello(ctx context.Context, req *pb.HelloRequest) (*pb.HelloReply, error) { 51 | reply := &pb.HelloReply{} 52 | reply.Message = "hello " + req.Name 53 | return reply, nil 54 | } 55 | 56 | func main() { 57 | cont := continuous.New() 58 | 59 | // srv1 implements Continuous 60 | srv1 := &httpServer{Server: &http.Server{Handler: &httpd{}}} 61 | cont.AddServer(srv1, &continuous.ListenOn{"tcp", ":8000"}) 62 | cont.AddServer(srv1, &continuous.ListenOn{"tcp", ":8001"}) 63 | cont.AddServer(srv1, &continuous.ListenOn{"tcp", ":8002"}) 64 | 65 | // srv2 implements Continuous 66 | srv2 := &grpcServer{Server: grpc.NewServer()} 67 | pb.RegisterGreeterServer(srv2.Server, &helloServer{}) 68 | cont.AddServer(srv2, &continuous.ListenOn{"tcp", ":50051"}) 69 | cont.AddServer(srv2, &continuous.ListenOn{"tcp", ":50052"}) 70 | cont.AddServer(srv2, &continuous.ListenOn{"tcp", ":50053"}) 71 | 72 | if err := cont.Serve(); err != nil { 73 | fmt.Println(err) 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /continuous.go: -------------------------------------------------------------------------------- 1 | package continuous 2 | 3 | import ( 4 | "crypto/tls" 5 | "fmt" 6 | "io" 7 | "io/ioutil" 8 | "net" 9 | "os" 10 | "os/signal" 11 | "sync" 12 | "syscall" 13 | 14 | gnet "github.com/facebookgo/grace/gracenet" 15 | "go.uber.org/zap" 16 | "go.uber.org/zap/zapcore" 17 | ) 18 | 19 | // Continuous is the interface of a basic server 20 | type Continuous interface { 21 | Serve(lis net.Listener) error 22 | Stop() error 23 | GracefulStop() error 24 | } 25 | 26 | // Cont keeps your server which implement the Continuous continuously 27 | type Cont struct { 28 | net gnet.Net 29 | name string 30 | pid int 31 | child int 32 | pidfile string 33 | cwd string 34 | logger *zap.Logger 35 | servers []*ContServer 36 | state ContState 37 | wg sync.WaitGroup 38 | doneChan chan struct{} 39 | } 40 | 41 | // ContState indicates the state of Cont 42 | type ContState int 43 | 44 | const ( 45 | Running ContState = iota 46 | Ready 47 | Stopped 48 | ) 49 | 50 | func (cs ContState) String() string { 51 | switch cs { 52 | case Running: 53 | return "running" 54 | case Stopped: 55 | return "stopped" 56 | case Ready: 57 | return "ready" 58 | } 59 | return "" 60 | } 61 | 62 | // ListenOn some network and address 63 | type ListenOn struct { 64 | Network string 65 | Address string 66 | } 67 | 68 | // ContServer combines listener, addresss and a continuous 69 | type ContServer struct { 70 | lis net.Listener 71 | srv Continuous 72 | listenOn *ListenOn 73 | tlsConfig *tls.Config 74 | upgrader func(lis net.Listener) net.Listener 75 | } 76 | 77 | // Option to new a Cont 78 | type Option func(cont *Cont) 79 | 80 | // ProcName custom the procname, use os.Args[0] if not set 81 | func ProcName(name string) Option { 82 | return func(cont *Cont) { 83 | cont.name = name 84 | } 85 | } 86 | 87 | // WorkDir custom the work dir, use os.Getwd() if not set 88 | func WorkDir(path string) Option { 89 | return func(cont *Cont) { 90 | cont.cwd = path 91 | } 92 | } 93 | 94 | // LoggerOutput sets a io.Writer to output log 95 | func LoggerOutput(out io.Writer) Option { 96 | return func(cont *Cont) { 97 | core := zapcore.NewCore(zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()), 98 | zapcore.AddSync(out), zap.NewAtomicLevelAt(zapcore.InfoLevel)) 99 | replace := func(c zapcore.Core) zapcore.Core { 100 | return core 101 | } 102 | cont.logger = cont.logger.WithOptions(zap.WrapCore(replace)) 103 | } 104 | } 105 | 106 | // PidFile custom the pid file path 107 | func PidFile(filename string) Option { 108 | return func(cont *Cont) { 109 | cont.pidfile = filename 110 | } 111 | } 112 | 113 | // New creates a Cont object which upgrades binary continuously 114 | func New(opts ...Option) *Cont { 115 | dir, _ := os.Getwd() 116 | cont := &Cont{name: os.Args[0], cwd: dir, pid: os.Getpid()} 117 | logger, err := zap.NewProduction(zap.AddCaller()) 118 | if err != nil { 119 | fmt.Println(err) 120 | os.Exit(-1) 121 | } 122 | 123 | cont.logger = logger.With(zap.Int("pid", os.Getpid())) 124 | 125 | for _, o := range opts { 126 | o(cont) 127 | } 128 | 129 | if cont.pidfile == "" { 130 | cont.pidfile = cont.cwd + "/" + cont.name + ".pid" 131 | } 132 | 133 | return cont 134 | } 135 | 136 | type ServerOption func(cs *ContServer) 137 | 138 | func TLSConfig(c *tls.Config) ServerOption { 139 | return func(cs *ContServer) { 140 | cs.tlsConfig = c 141 | } 142 | } 143 | 144 | // ListenerUpgrader upgrade a raw listener to a higher level listener 145 | func ListenerUpgrader(upgrader func(lis net.Listener) net.Listener) ServerOption { 146 | return func(cs *ContServer) { 147 | cs.upgrader = upgrader 148 | } 149 | } 150 | 151 | // AddServer and a server which implement Continuous interface 152 | // the added server will start to listen to the socket, but it only accept connections after serving 153 | func (cont *Cont) AddServer(srv Continuous, listenOn *ListenOn, opts ...ServerOption) error { 154 | cs := &ContServer{srv: srv, listenOn: listenOn} 155 | for _, o := range opts { 156 | o(cs) 157 | } 158 | lis, err := cont.net.Listen(listenOn.Network, listenOn.Address) 159 | if err != nil { 160 | return err 161 | } 162 | if cs.tlsConfig != nil { 163 | lis = tls.NewListener(lis, cs.tlsConfig) 164 | } 165 | if cs.upgrader != nil { 166 | lis = cs.upgrader(lis) 167 | } 168 | cs.lis = lis 169 | cont.servers = append(cont.servers, cs) 170 | return nil 171 | } 172 | 173 | // Serve run all the servers and wait to handle signals 174 | func (cont *Cont) Serve() error { 175 | cont.logger.Debug("continuous serving") 176 | if err := cont.writePid(); err != nil { 177 | return err 178 | } 179 | 180 | if err := cont.serve(); err != nil { 181 | return err 182 | } 183 | 184 | c := make(chan os.Signal, 1) 185 | signal.Notify(c, syscall.SIGTERM, syscall.SIGINT, syscall.SIGUSR2, syscall.SIGUSR1, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGCHLD) 186 | cont.logger.Debug("waiting for signals") 187 | 188 | for { 189 | sig := <-c 190 | cont.logger.Info("got signal", zap.Stringer("value", sig)) 191 | switch sig { 192 | case syscall.SIGTERM, syscall.SIGINT: 193 | cont.Stop() 194 | return nil 195 | case syscall.SIGQUIT: 196 | cont.GracefulStop() 197 | return nil 198 | case syscall.SIGUSR1: 199 | if cont.state == Running { 200 | cont.state = Ready 201 | cont.closeListeners() 202 | } else if cont.state == Ready { 203 | cont.wg.Wait() //wait server goroutines to exit 204 | //listen and serve again 205 | if err := cont.openListeners(); err != nil { 206 | cont.logger.Error("open listeners failed", zap.Error(err)) 207 | continue 208 | } 209 | if err := cont.serve(); err != nil { 210 | cont.logger.Error("start serve failed", zap.Error(err)) 211 | continue 212 | } 213 | cont.state = Running 214 | } 215 | 216 | case syscall.SIGUSR2: 217 | if err := cont.upgrade(); err != nil { 218 | cont.logger.Error("upgrade binary failed", zap.Error(err)) 219 | } 220 | 221 | case syscall.SIGHUP: 222 | if err := cont.upgrade(); err != nil { 223 | cont.logger.Error("upgrade binary failed", zap.Error(err)) 224 | continue 225 | } 226 | if err := cont.GracefulStop(); err != nil { 227 | cont.logger.Error("upgrade binary failed", zap.Error(err)) 228 | continue 229 | } 230 | return nil 231 | case syscall.SIGCHLD: 232 | p, err := os.FindProcess(cont.child) 233 | if err != nil { 234 | cont.logger.Error("find process failed", zap.Error(err)) 235 | } 236 | // wait child process to exit to avoid zombie process 237 | status, err := p.Wait() 238 | if err != nil { 239 | cont.logger.Error("wait child process to exit failed", zap.Error(err)) 240 | } else { 241 | if status.Success() { 242 | cont.logger.Info("child exited", zap.Stringer("status", status)) 243 | } else { 244 | cont.logger.Error("child exited failed", zap.Stringer("status", status)) 245 | } 246 | } 247 | 248 | // recover pidfile.old to pidfile 249 | if err := os.Rename(cont.pidfile+".old", cont.pidfile); err != nil { 250 | cont.logger.Error("recover pid file failed", zap.Error(err)) 251 | } 252 | } 253 | } 254 | } 255 | 256 | // Stop the server immediately 257 | func (cont *Cont) Stop() error { 258 | if cont.doneChan != nil { 259 | close(cont.doneChan) 260 | } 261 | for _, server := range cont.servers { 262 | if err := server.srv.Stop(); err != nil { 263 | return err 264 | } 265 | } 266 | cont.state = Stopped 267 | return nil 268 | } 269 | 270 | // GracefulStop the server 271 | func (cont *Cont) GracefulStop() error { 272 | if cont.doneChan != nil { 273 | close(cont.doneChan) 274 | } 275 | for _, server := range cont.servers { 276 | if err := server.srv.GracefulStop(); err != nil { 277 | return err 278 | } 279 | } 280 | cont.state = Stopped 281 | return nil 282 | } 283 | 284 | func (cont *Cont) upgrade() error { 285 | // rename pidfile to pidfile.old 286 | if err := os.Rename(cont.pidfile, cont.pidfile+".old"); err != nil { 287 | cont.logger.Warn("rename pid file failed", zap.Error(err)) 288 | } 289 | 290 | pid, err := cont.net.StartProcess() 291 | if err != nil { 292 | return err 293 | } 294 | cont.logger.Info("new process started", zap.Int("child", pid)) 295 | cont.child = pid 296 | return nil 297 | } 298 | 299 | func (cont *Cont) closeListeners() { 300 | // close chan to notify Serve to exit and ignore 301 | if cont.doneChan != nil { 302 | close(cont.doneChan) 303 | } 304 | 305 | for _, server := range cont.servers { 306 | if err := server.lis.Close(); err != nil { 307 | cont.logger.Error("close listener failed", zap.Error(err), zap.String("listenon", server.listenOn.Address)) 308 | } 309 | } 310 | // gracenet internal stores all the active listeners. When we close listeners here, we can not notify gracenet about this 311 | // so it will keep those closed listeners and try to pass to child process which cause errors, so we reinit net here 312 | cont.net = gnet.Net{} 313 | } 314 | 315 | func (cont *Cont) openListeners() error { 316 | for _, server := range cont.servers { 317 | lis, err := cont.net.Listen(server.listenOn.Network, server.listenOn.Address) 318 | if err != nil { 319 | return err 320 | } 321 | if server.upgrader != nil { 322 | lis = server.upgrader(lis) 323 | } 324 | server.lis = lis 325 | if server.tlsConfig != nil { 326 | server.lis = tls.NewListener(lis, server.tlsConfig) 327 | } 328 | } 329 | return nil 330 | } 331 | 332 | func (cont *Cont) serve() error { 333 | cont.doneChan = make(chan struct{}) 334 | 335 | for _, server := range cont.servers { 336 | cont.wg.Add(1) 337 | go func(server *ContServer) { 338 | done := false 339 | if err := server.srv.Serve(server.lis); err != nil { 340 | select { 341 | case <-cont.doneChan: 342 | done = true // ignore error which caused by Stop/GracefulStop 343 | cont.logger.Debug("serve close", zap.String("listen", server.listenOn.Address)) 344 | default: 345 | } 346 | if !done { 347 | cont.logger.Error("serve failed", zap.Error(err), zap.String("listen", server.listenOn.Address)) 348 | } 349 | } 350 | cont.wg.Done() 351 | }(server) 352 | } 353 | 354 | cont.state = Running 355 | return nil 356 | } 357 | 358 | func (cont *Cont) writePid() error { 359 | return ioutil.WriteFile(cont.pidfile, []byte(fmt.Sprint(cont.pid)), 0644) 360 | } 361 | 362 | // Status return the current status 363 | func (cont *Cont) Status() ContState { 364 | return cont.state 365 | } 366 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------