{"id":13461349,"url":"https://github.com/cloudflare/tableflip","last_synced_at":"2025-05-13T15:09:22.716Z","repository":{"id":38904260,"uuid":"148815853","full_name":"cloudflare/tableflip","owner":"cloudflare","description":"Graceful process restarts in Go","archived":false,"fork":false,"pushed_at":"2024-09-25T22:41:58.000Z","size":83,"stargazers_count":2967,"open_issues_count":12,"forks_count":150,"subscribers_count":38,"default_branch":"master","last_synced_at":"2025-04-23T18:53:39.814Z","etag":null,"topics":["go","golang","graceful-restarts"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cloudflare.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-09-14T16:37:37.000Z","updated_at":"2025-04-16T16:51:39.000Z","dependencies_parsed_at":"2024-01-06T01:03:18.999Z","dependency_job_id":"3648ed0c-da2b-4b4e-826a-33474cce0e0c","html_url":"https://github.com/cloudflare/tableflip","commit_stats":{"total_commits":64,"total_committers":15,"mean_commits":4.266666666666667,"dds":0.375,"last_synced_commit":"b3a0d54308fba327fb463cc1a3c11d3607deea53"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudflare%2Ftableflip","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudflare%2Ftableflip/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudflare%2Ftableflip/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudflare%2Ftableflip/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cloudflare","download_url":"https://codeload.github.com/cloudflare/tableflip/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253969239,"owners_count":21992262,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang","graceful-restarts"],"created_at":"2024-07-31T11:00:35.471Z","updated_at":"2025-05-13T15:09:17.702Z","avatar_url":"https://github.com/cloudflare.png","language":"Go","readme":"# Graceful process restarts in Go\n\n[![](https://godoc.org/github.com/cloudflare/tableflip?status.svg)](https://godoc.org/github.com/cloudflare/tableflip)\n\nIt is sometimes useful to update the running code and / or configuration of a\nnetwork service, without disrupting existing connections. Usually, this is\nachieved by starting a new process, somehow transferring clients to it and\nthen exiting the old process.\n\nThere are [many ways to implement graceful upgrades](https://blog.cloudflare.com/graceful-upgrades-in-go/).\nThey vary wildly in the trade-offs they make, and how much control they afford the user. This library\nhas the following goals:\n\n* No old code keeps running after a successful upgrade\n* The new process has a grace period for performing initialisation\n* Crashing during initialisation is OK\n* Only a single upgrade is ever run in parallel\n\n**`tableflip` works on Linux and macOS.**\n\n## Using the library\n\n```Go\nupg, _ := tableflip.New(tableflip.Options{})\ndefer upg.Stop()\n\ngo func() {\n\tsig := make(chan os.Signal, 1)\n\tsignal.Notify(sig, syscall.SIGHUP)\n\tfor range sig {\n\t\tupg.Upgrade()\n\t}\n}()\n\n// Listen must be called before Ready\nln, _ := upg.Listen(\"tcp\", \"localhost:8080\")\ndefer ln.Close()\n\ngo http.Serve(ln, nil)\n\nif err := upg.Ready(); err != nil {\n\tpanic(err)\n}\n\n\u003c-upg.Exit()\n```\n\nPlease see the more elaborate [graceful shutdown with net/http](http_example_test.go) example.\n\n## Integration with `systemd`\n\n```text\n[Unit]\nDescription=Service using tableflip\n\n[Service]\nExecStart=/path/to/binary -some-flag /path/to/pid-file\nExecReload=/bin/kill -HUP $MAINPID\nPIDFile=/path/to/pid-file\n```\n\nSee the [documentation](https://godoc.org/github.com/cloudflare/tableflip) as well.\n\nThe logs of a process using `tableflip` may go missing due to a [bug in journald](https://github.com/systemd/systemd/issues/13708),\nwhich has been fixed by systemd v244 release. If you are running an older version\nof systemd, you can work around this by logging directly to journald, for example\nby using [go-systemd/journal](https://godoc.org/github.com/coreos/go-systemd/journal)\nand looking for the [$JOURNAL_STREAM](https://www.freedesktop.org/software/systemd/man/systemd.exec.html#$JOURNAL_STREAM)\nenvironment variable.\n","funding_links":[],"categories":["Go","开源类库","Open source library","Repositories","Infrastructure \u0026 Operations"],"sub_categories":["优雅升级","Elegant Upgrade","Deployment \u0026 Management"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudflare%2Ftableflip","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcloudflare%2Ftableflip","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudflare%2Ftableflip/lists"}