Gracehttp: Graceful Restart Go program (hot start)

Source: Internet
Author: User

Issue background

When the application restarts, http if the kill -9 program exits directly and then starts, there are several issues:

    1. The old request has not been processed and if the server process exits directly, it will cause the client link to be interrupted (received RST );
    2. New request to call, the service has not been restarted, causingconnection refused

These problems can lead to bad customer experience, serious and even affect the customer's business. So, we need to gracefully restart our application.

Solving problems--Elegance

Github:gracehttp

Principle

    1. signal mechanism;
    2. The child process inherits the resources of the parent process;

Support Features

    1. Smooth restart (zero-downtime restart server);
    2. Smooth off;
    3. Serveradd more (include HTTP , HTTPS );
    4. Custom log components;

User Guide

Add Server

    // http    srv1 := &http.Server{        Addr:    ":80",        Handler: sc,    }    gracehttp.AddServer(srv1, false, "", "")    // https    srv2 := &http.Server{        Addr:    ":443",        Handler: sc,    }    gracehttp.AddServer(srv2, true, "../config/https.crt", "../config/https.key")    gracehttp.Run() // 此方法会阻塞,直到所有的 HTTP 服务退出

As shown above, just create a good Server object and call gracehttp.AddServer Add.

Adding custom log Components

    gracehttp.SetErrorLogCallback(logger.LogConfigLoadError)

There are three methods available here Set* that correspond to different log levels:

    • Setinfologcallback
    • Setnoticelogcallback
    • Seterrorlogcallback

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.