{"id":13367311,"url":"https://github.com/VividCortex/Godaemon","last_synced_at":"2025-03-12T18:32:24.234Z","repository":{"id":9834161,"uuid":"11822870","full_name":"VividCortex/godaemon","owner":"VividCortex","description":"Daemonize Go applications deviously.","archived":false,"fork":false,"pushed_at":"2021-06-29T04:55:28.000Z","size":36,"stargazers_count":493,"open_issues_count":9,"forks_count":53,"subscribers_count":30,"default_branch":"master","last_synced_at":"2024-08-03T15:06:05.719Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/VividCortex.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}},"created_at":"2013-08-01T17:16:30.000Z","updated_at":"2024-07-15T06:11:23.000Z","dependencies_parsed_at":"2022-08-26T14:20:25.456Z","dependency_job_id":null,"html_url":"https://github.com/VividCortex/godaemon","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VividCortex%2Fgodaemon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VividCortex%2Fgodaemon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VividCortex%2Fgodaemon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VividCortex%2Fgodaemon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/VividCortex","download_url":"https://codeload.github.com/VividCortex/godaemon/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221309967,"owners_count":16795837,"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-07-30T00:01:44.238Z","updated_at":"2024-10-24T11:31:11.780Z","avatar_url":"https://github.com/VividCortex.png","language":"Go","readme":"godaemon\n========\n\nDaemonize Go applications with `exec()` instead of `fork()`. Read our [blog post](https://vividcortex.com/blog/2013/08/27/godaemon-a-library-to-daemonize-go-apps/) on the subject.\n\nYou can't daemonize the usual way in Go. Daemonizing is a Unix concept that requires\nsome [specific things](http://goo.gl/vTUsVy) you can't do\neasily in Go. But you can still accomplish the same goals \nif you don't mind that your program will start copies of itself\nseveral times, as opposed to using `fork()` the way many programmers are accustomed to doing.\n\nIt is somewhat controversial whether it's even a good idea to make programs daemonize themselves,\nor how to do it correctly (and whether it's even possible to do correctly in Go).\nRead [here](https://code.google.com/p/go/issues/detail?id=227),\n[here](http://www.ryanday.net/2012/09/04/the-problem-with-a-golang-daemon/),\nand [here](http://stackoverflow.com/questions/14537045/how-i-should-run-my-golang-process-in-background)\nfor more on this topic. However, at [VividCortex](https://vividcortex.com/) we do need to run one of our processes as a\ndaemon with the usual attributes of a daemon, and we chose the approach implemented in this package.\n\nBecause of the factors mentioned in the first link just given, you should take great care when\nusing this package's approach. It works for us, because we don't do anything like starting up\ngoroutines in our `init()` functions, or other things that are perfectly legal in Go in general.\n\n## Getting Started\n\nView the [package documentation](http://godoc.org/github.com/VividCortex/godaemon)\nfor details about how it works. Briefly, to make your program into a daemon,\ndo the following as soon as possible in your `main()` function:\n\n```go\nimport (\n\t\"github.com/VividCortex/godaemon\"\n)\n\nfunc main() {\n\tgodaemon.MakeDaemon(\u0026godaemon.DaemonAttr{})\n}\n```\n\nUse the `CaptureOutput` attribute if you need to capture your program's\nstandard output and standard error streams. In that case, the function returns\ntwo valid readers (`io.Reader`) that you can read from the program itself.\nThat's particularly useful for functions that write error or diagnosis messages\nright to the error output, which are normally lost in a daemon.\n\nUse the `Files` attribute if you need to inherit open files into the daemon.\nThis is primarily intended for avoiding race conditions when holding locks on\nthose files (flocks). Releasing and re-acquiring locks between successive fork\ncalls opens up the chance for another program to steal the lock. However, by\ndeclaring your file descriptors in the `Files` attribute, `MakeDaemon()` will\nguarantee that locks are not released throughout the whole process. Your daemon\nwill inherit the file still holding the same locks, with no other process having\nintervened in between. See the\n[package documentation](http://godoc.org/github.com/VividCortex/godaemon) for\nmore details and sample code. (Note that you shouldn't use this feature to\ninherit TTY descriptors; otherwise what you get is technically not a daemon.)\n\n\n## Contribute\n\nContributions are welcome. Please open pull requests or issue reports!\n\n\n## License\n\nThis repository is Copyright (c) 2013 VividCortex, Inc. All rights reserved.\nIt is licensed under the MIT license. Please see the LICENSE file for applicable\nlicense terms.\n\n## Authors\n\nThe primary author is [Gustavo Kristic](https://github.com/gkristic), with some\ndocumentation and other minor contributions by others at VividCortex.\n\n## History\n\nAn earlier version of this concept with a slightly different interface was\ndeveloped internally at VividCortex.\n\n## Cats\n\nA Go Daemon is a good thing, and so we present an angelic cat picture:\n\n![Angelic Cat](http://f.cl.ly/items/2b0y0n3W2W1H0S1K3g0g/angelic-cat.jpg)\n","funding_links":[],"categories":["实用工具","實用工具"],"sub_categories":["高级控制台界面","高級控制台界面"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FVividCortex%2FGodaemon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FVividCortex%2FGodaemon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FVividCortex%2FGodaemon/lists"}