All Projects → kuangchanglang → Graceful

kuangchanglang / Graceful

Licence: mit
graceful reload golang http server, zero downtime, compatible with systemd, supervisor

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Graceful

supervisor-rs
Lite Rust version of supervisor, inspired by python version
Stars: ✭ 34 (-73.64%)
Mutual labels:  systemd, supervisor
Freenom Dns Updater
A tool to update freenom's dns records
Stars: ✭ 117 (-9.3%)
Mutual labels:  systemd
Gnome Shell Extension Services Systemd
Gnome Shell Extension that allows to start and stop systemd services
Stars: ✭ 68 (-47.29%)
Mutual labels:  systemd
Systemdlogger
Exports systemd logs to an external service, eg cloudwatch, elasticsearch
Stars: ✭ 91 (-29.46%)
Mutual labels:  systemd
Arch Linux Install
My Arch Linux installation notes
Stars: ✭ 72 (-44.19%)
Mutual labels:  systemd
Selfhosted
rootless docker compose + traefik
Stars: ✭ 97 (-24.81%)
Mutual labels:  systemd
Sway De
🏠 Sway desktop environment dotfile installation for Arch Linux
Stars: ✭ 63 (-51.16%)
Mutual labels:  systemd
Go Systemd
Go bindings to systemd socket activation, journal, D-Bus, and unit files
Stars: ✭ 1,756 (+1261.24%)
Mutual labels:  systemd
Log2ram
ramlog like for systemd (Put log into a ram folder)
Stars: ✭ 1,751 (+1257.36%)
Mutual labels:  systemd
Earl
Service Objects for Crystal (Agents, Artists, Supervisors, Pools, ...)
Stars: ✭ 89 (-31.01%)
Mutual labels:  supervisor
Graphite Metrics
metric collectors for various stuff not (or poorly) handled by other monitoring daemons
Stars: ✭ 85 (-34.11%)
Mutual labels:  systemd
Hassctl
Simple command line utility to help debug Home Assistant configuration
Stars: ✭ 77 (-40.31%)
Mutual labels:  systemd
Sleepto
An alternative to traditional task schedulers
Stars: ✭ 98 (-24.03%)
Mutual labels:  systemd
Ansible Prometheus
Ansible playbook for installing Prometheus monitoring system, exporters such as: node, snmp, blackbox, thus alert manager and push gateway
Stars: ✭ 69 (-46.51%)
Mutual labels:  systemd
Capistrano Mb
[unmaintained] Capistrano tasks for deploying Rails from scratch to Ubuntu 16.04 and 18.04
Stars: ✭ 117 (-9.3%)
Mutual labels:  systemd
Systemd Named Netns
Use named netns (net namespace) with systemd services!
Stars: ✭ 63 (-51.16%)
Mutual labels:  systemd
Localslackirc
IRC gateway for slack, running on localhost for one user
Stars: ✭ 84 (-34.88%)
Mutual labels:  systemd
Supervisor Event Listener
Supervisor事件通知, 支持邮件, Slack, WebHook
Stars: ✭ 95 (-26.36%)
Mutual labels:  supervisor
Fluent Plugin Systemd
This is a fluentd input plugin. It reads logs from the systemd journal.
Stars: ✭ 124 (-3.88%)
Mutual labels:  systemd
Asus Fan Control
🌀 Fan control for ASUS devices running Linux.
Stars: ✭ 120 (-6.98%)
Mutual labels:  systemd

graceful

Inspired by overseer and endless, with minimum codes and handy api to make http server graceful.

Prerequisite

  • golang 1.8+
  • linux/darwin(windows not supported)

Feature

  • Graceful reload http servers, zero downtime on upgrade.
  • Compatible with systemd, supervisor, etc.
  • Drop-in placement for http.ListenAndServe

Example

    type handler struct {
    }

    func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
        fmt.Fprintf(w, "Hello, port: %v, %q", r.Host, html.EscapeString(r.URL.Path))
    }

    func main(){
	    graceful.ListenAndServe(":9222", &handler{})
    }

multi servers:

    func main(){
        server := graceful.NewServer()
        server.Register("0.0.0.0:9223", &handler{})
        server.Register("0.0.0.0:9224", &handler{})
        server.Register("0.0.0.0:9225", &handler{})
        err := server.Run()
        fmt.Printf("error: %v\n", err)
    }

More example checkout example folder.

Reload

SIGHUP and SIGUSR1 on master proccess are used as default to reload server. server.Reload() func works as well from your code.

Drawbacks

graceful starts a master process to keep pid unchaged for process managers(systemd, supervisor, etc.), and a worker proccess listen to actual addrs. That means graceful starts one more process. Fortunately, master proccess waits for signals and reload worker when neccessary, which is costless since reload is usually low-frequency action.

Default values

  • StopTimeout. Unfinished old connections will be drop in {StopTimeout} seconds, default 20s, after new server is up.
	server := graceful.NewServer(graceful.WithStopTimeout(time.Duration(4 * time.Hour)))
	server.Register(addr, handler)
	if err := server.Run(); err != nil {
		log.Fatal(err)
	}
  • Signals. Default reload signals: syscall.SIGHUP, syscall.SIGUSR1 and stop signals: syscall.SIGKILL, syscall.SIGTERM, syscall.SIGINT could be overwrited with:
	server := graceful.NewServer(graceful.WithStopSignals([]syscall.Signal{syscall.SIGKILL}), graceful.WithReloadSignals([]syscall.Signal{syscall.SIGHUP}))
	server.Register(addr, handler)
	if err := server.Run(); err != nil {
		log.Fatal(err)
	}

TODO

  • ListenAndServeTLS
  • Add alternative api: Run in single process without master-worker
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].