{"id":18832687,"url":"https://github.com/linka-cloud/go-fork-listener","last_synced_at":"2026-01-25T19:30:20.407Z","repository":{"id":61626044,"uuid":"542629316","full_name":"linka-cloud/go-fork-listener","owner":"linka-cloud","description":null,"archived":false,"fork":false,"pushed_at":"2022-09-28T15:20:00.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-30T07:21:54.185Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/linka-cloud.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-09-28T14:20:19.000Z","updated_at":"2022-09-28T14:23:55.000Z","dependencies_parsed_at":"2022-10-18T18:00:42.798Z","dependency_job_id":null,"html_url":"https://github.com/linka-cloud/go-fork-listener","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linka-cloud%2Fgo-fork-listener","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linka-cloud%2Fgo-fork-listener/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linka-cloud%2Fgo-fork-listener/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linka-cloud%2Fgo-fork-listener/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/linka-cloud","download_url":"https://codeload.github.com/linka-cloud/go-fork-listener/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239768926,"owners_count":19693763,"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":[],"created_at":"2024-11-08T01:58:43.822Z","updated_at":"2026-01-25T19:30:18.231Z","avatar_url":"https://github.com/linka-cloud.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-fork-listener\n\n[![Language: Go](https://img.shields.io/badge/lang-Go-6ad7e5.svg?style=flat-square\u0026logo=go)](https://golang.org/)\n[![Go Reference](https://pkg.go.dev/badge/go.linka.cloud/go-fork-listener.svg)](https://pkg.go.dev/go.linka.cloud/go-fork-listener)\n\nGo package for listening on a socket and forking a detached child process on each connection.\n\nThis is useful if you need to be able to restart a process without interrupting any connections, like *sshd*.\n\n**Only unix like systems are supported as the connection is passed to the child process via file descriptor.**\n\n## Usage\n\n```go\nimport fork \"go.linka.cloud/go-fork-listener\"\n```\n\n## Example\n\n\n### Simple http server\n\n```go\npackage main\n\nimport (\n\t\"net/http\"\n\t\"os\"\n\n\t\"github.com/sirupsen/logrus\"\n\n\t\"go.linka.cloud/go-fork-listener\"\n)\n\nfunc main() {\n\tlogrus.SetLevel(logrus.DebugLevel)\n\tlogrus.Infof(\"running with pid %d\", os.Getpid())\n\tlis, err := fork.Listen(\"tcp\", \":8080\")\n\tif err != nil {\n\t\tlogrus.Fatal(err)\n\t}\n\tdefer lis.Close()\n\tif err := http.Serve(lis, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {\n\t\tif _, err := w.Write([]byte(\"Hello from child process!\\n\")); err != nil {\n\t\t\tlogrus.Error(err)\n\t\t}\n\t})); err != nil \u0026\u0026 !fork.IsClosed(err) {\n\t\tlogrus.Fatal(err)\n\t}\n}\n```\n\n### Fork aware http server\n\n```go\npackage main\n\nimport (\n\t\"net/http\"\n\t\"os\"\n\n\t\"github.com/sirupsen/logrus\"\n\n\t\"go.linka.cloud/go-fork-listener\"\n)\n\nfunc main() {\n\tlogrus.SetLevel(logrus.DebugLevel)\n\tlogrus.Infof(\"running with pid %d\", os.Getpid())\n\tlis, err := fork.Listen(\"tcp\", \":8080\")\n\tif err != nil {\n\t\tlogrus.Fatal(err)\n\t}\n\tdefer lis.Close()\n\n\tif lis.IsParent() {\n\t\t// do some configuration checks or other things that need to be done only once\n\t\tif err := lis.Run(); err != nil {\n\t\t\tlogrus.Fatal(err)\n\t\t}\n\t\treturn\n\t}\n\n\t// do some handler dependencies initialization\n\n\tif err := http.Serve(lis, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {\n\t\tif _, err := w.Write([]byte(\"Hello from child process!\\n\")); err != nil {\n\t\t\tlogrus.Error(err)\n\t\t}\n\t})); err != nil \u0026\u0026 !fork.IsClosed(err) {\n\t\tlogrus.Fatal(err)\n\t}\n}\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinka-cloud%2Fgo-fork-listener","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flinka-cloud%2Fgo-fork-listener","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinka-cloud%2Fgo-fork-listener/lists"}