tableflip

在Go中优雅地重新启动进程。(Graceful process restarts in Go)

  • 所有者: cloudflare/tableflip
  • 平台: Linux, Mac, Windows
  • 許可證: BSD 3-Clause "New" or "Revised" License
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

Graceful process restarts in Go

It is sometimes useful to update the running code and / or configuration of a
network service, without disrupting existing connections. Usually, this is
achieved by starting a new process, somehow transferring clients to it and
then exiting the old process.

There are many ways to implement graceful upgrades.
They vary wildly in the trade-offs they make, and how much control they afford the user. This library
has the following goals:

  • No old code keeps running after a successful upgrade
  • The new process has a grace period for performing initialisation
  • Crashing during initialisation is OK
  • Only a single upgrade is ever run in parallel

tableflip works on Linux and macOS.

Using the library

upg, _ := tableflip.New(tableflip.Options{})
defer upg.Stop()

go func() {
	sig := make(chan os.Signal, 1)
	signal.Notify(sig, syscall.SIGHUP)
	for range sig {
		upg.Upgrade()
	}
}()

// Listen must be called before Ready
ln, _ := upg.Listen("tcp", "localhost:8080")
defer ln.Close()

go http.Serve(ln, nil)

if err := upg.Ready(); err != nil {
	panic(err)
}

<-upg.Exit()

Please see the more elaborate graceful shutdown with net/http example.

Integration with systemd

[Unit]
Description=Service using tableflip

[Service]
ExecStart=/path/to/binary -some-flag /path/to/pid-file
ExecReload=/bin/kill -HUP $MAINPID
PIDFile=/path/to/pid-file

See the documentation as well.

The logs of a process using tableflip may go missing due to a bug in journald. You can work around this by logging directly to journald, for example by using go-systemd/journal and looking for the $JOURNAL_STREAM environment variable.

主要指標

概覽
名稱與所有者cloudflare/tableflip
主編程語言Go
編程語言Go (語言數: 1)
平台Linux, Mac, Windows
許可證BSD 3-Clause "New" or "Revised" License
所有者活动
創建於2018-09-14 16:37:37
推送於2024-09-25 22:41:58
最后一次提交2024-09-19 21:53:15
發布數6
最新版本名稱v1.2.3 (發布於 )
第一版名稱v1.0.0 (發布於 )
用户参与
星數3k
關注者數38
派生數151
提交數67
已啟用問題?
問題數27
打開的問題數8
拉請求數33
打開的拉請求數4
關閉的拉請求數9
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?