{"id":13481623,"url":"https://github.com/sevlyar/go-daemon","last_synced_at":"2025-05-13T21:07:55.191Z","repository":{"id":9510142,"uuid":"11405722","full_name":"sevlyar/go-daemon","owner":"sevlyar","description":"A library for writing system daemons in golang.","archived":false,"fork":false,"pushed_at":"2024-07-23T08:33:26.000Z","size":185,"stargazers_count":2250,"open_issues_count":25,"forks_count":250,"subscribers_count":59,"default_branch":"master","last_synced_at":"2025-05-06T19:44:47.401Z","etag":null,"topics":["daemon","go","golang","library","pid","pidfile"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sevlyar.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":"2013-07-14T16:33:10.000Z","updated_at":"2025-05-06T06:28:06.000Z","dependencies_parsed_at":"2023-02-16T09:31:38.411Z","dependency_job_id":"32b5c3b7-be0e-4054-a87f-f5f09c47ad0e","html_url":"https://github.com/sevlyar/go-daemon","commit_stats":{"total_commits":139,"total_committers":26,"mean_commits":5.346153846153846,"dds":"0.28057553956834536","last_synced_commit":"c2a11b2b57fc02ca556fde5ff76b510aa59a0b9a"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sevlyar%2Fgo-daemon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sevlyar%2Fgo-daemon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sevlyar%2Fgo-daemon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sevlyar%2Fgo-daemon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sevlyar","download_url":"https://codeload.github.com/sevlyar/go-daemon/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253552278,"owners_count":21926457,"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":["daemon","go","golang","library","pid","pidfile"],"created_at":"2024-07-31T17:00:53.463Z","updated_at":"2025-05-13T21:07:50.161Z","avatar_url":"https://github.com/sevlyar.png","language":"Go","funding_links":[],"categories":["开源类库","Go","Open source library","Repositories"],"sub_categories":["命令行","Command Line"],"readme":"# go-daemon [![Build Status](https://travis-ci.org/sevlyar/go-daemon.svg?branch=master)](https://travis-ci.org/sevlyar/go-daemon) [![GoDoc](https://godoc.org/github.com/sevlyar/go-daemon?status.svg)](https://godoc.org/github.com/sevlyar/go-daemon)\n\nLibrary for writing system daemons in Go.\n\nNow supported only UNIX-based OS (Windows is not supported). But the library was tested only on Linux\nand OSX, so that if you have an ability to test the library on other platforms, give me feedback, please (#26).\n\n*Please, feel free to send me bug reports and fixes. Many thanks to all contributors.*\n\n## Features\n\n* Goroutine-safe daemonization;\n* Out of box work with pid-files;\n* Easy handling of system signals;\n* The control of a daemon.\n\n## Installation\n\n\tgo get github.com/sevlyar/go-daemon\n\nYou can use [gopkg.in](http://labix.org/gopkg.in):\n\n\tgo get gopkg.in/sevlyar/go-daemon.v0\n\nIf you want to use the library in production project, please use vendoring,\nbecause i can not ensure backward compatibility before release v1.0.\n\n## Examples\n\n* [Simple](examples/cmd/gd-simple/)\n* [Log rotation](examples/cmd/gd-log-rotation/)\n* [Signal handling](examples/cmd/gd-signal-handling/)\n\n## Documentation\n\n[godoc.org/github.com/sevlyar/go-daemon](https://godoc.org/github.com/sevlyar/go-daemon)\n\n## How it works\n\nWe can not use `fork` syscall in Golang's runtime, because child process doesn't inherit\nthreads and goroutines in that case. The library uses a simple trick: it runs its own copy with\na mark - a predefined environment variable. Availability of the variable for the process means\nan execution in the child's copy. So that if the mark is not setted - the library executes\nparent's operations and runs its own copy with mark, and if the mark is setted - the library\nexecutes child's operations:\n\n```go\nimport \"log\"\n\nfunc main() {\n\tPre()\n\n\tcontext := new(Context)\n\tchild, _ := context.Reborn()\n\n\tif child != nil {\n\t\tPostParent()\n\t} else {\n\t\tdefer func() {\n\t\t\tif err := context.Release(); err != nil {\n\t\t\t\tlog.Printf(\"Unable to release pid-file: %s\", err.Error())\n\t\t\t}\n\t\t}()\n\n\t\tPostChild()\n\t}\n}\n```\n\n![](img/idea.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsevlyar%2Fgo-daemon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsevlyar%2Fgo-daemon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsevlyar%2Fgo-daemon/lists"}