{"id":20148213,"url":"https://github.com/chainguard-dev/exitdir","last_synced_at":"2025-04-09T19:51:32.087Z","repository":{"id":42071115,"uuid":"481332293","full_name":"chainguard-dev/exitdir","owner":"chainguard-dev","description":"Common packages.","archived":false,"fork":false,"pushed_at":"2025-03-21T19:12:06.000Z","size":42,"stargazers_count":8,"open_issues_count":2,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-22T00:05:26.700Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chainguard-dev.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":"2022-04-13T18:34:08.000Z","updated_at":"2025-03-21T19:11:46.000Z","dependencies_parsed_at":"2024-06-19T05:36:34.305Z","dependency_job_id":"c07029ac-ed24-43d3-954f-e8349150e8a4","html_url":"https://github.com/chainguard-dev/exitdir","commit_stats":null,"previous_names":["chainguard-dev/pkg"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chainguard-dev%2Fexitdir","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chainguard-dev%2Fexitdir/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chainguard-dev%2Fexitdir/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chainguard-dev%2Fexitdir/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chainguard-dev","download_url":"https://codeload.github.com/chainguard-dev/exitdir/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248103901,"owners_count":21048244,"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-13T22:35:30.990Z","updated_at":"2025-04-09T19:51:32.060Z","avatar_url":"https://github.com/chainguard-dev.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ExitDir\n\nExitDir is a library to signal a process should exit via the filesystem.\n\n## Usage\n\nTo use this library, on the leader process:\n\n```go\npackage main\n\nimport \"chainguard.dev/exitdir\"\n\nfunc main() {\n\t// Signal the other processes should exit via a new file in `EXIT_DIR`.\n\tdefer exitdir.Exit();\n\t// ...rest of implementation.\n}\n```\n\nAnd then one or more follower processes:\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\n\t\"chainguard.dev/exitdir\"\n)\n\nfunc main() {\n\t// Decorate a context with ExitDir awareness. ExitDir will cancel the\n\t// returned context when a new file in `EXIT_DIR` is created.\n\tctx := exitdir.Aware(context.Background())\n\t// ...rest of implementation using `ctx` for lifecycle control.\n}\n```\n\n## Process Demo\n\nThis functionally is shown locally by using a temp directory and two processes:\n\n```shell\nexport EXIT_DIR=`mktemp -d`\ngo run ./cmd/follower \u0026\ngo run ./cmd/leader\n```\n\nResults in:\n\n```shell\n$ export EXIT_DIR=`mktemp -d`\n$ go run ./cmd/follower \u0026\n[1] 83528\n$ go run ./cmd/leader\n[Leader] Doing work...\n[Follower] Tick 0\n[Follower] Tick 1\n[Follower] Tick 2\n[Follower] Tick 3\n[Leader] Exiting...\n[Follower] Exiting...\n[1]+  Done                    go run ./cmd/follower\n$\n```\n\n## Kubernetes Demo\n\nOften in Kubernetes a job with multiple containers need to solve a problem of\nsignaling when to exit. If not coordinated, a resulting hung job looks like a\nfailure, but in-fact was successful except one container never exited.\n\n```shell\nko apply -f - \u003c\u003cEOF\napiVersion: batch/v1\nkind: Job\nmetadata:\n  name: example\nspec:\n  template:\n    spec:\n      restartPolicy: Never\n      containers:\n        - name: leader\n          image: ko://chainguard.dev/exitdir/cmd/leader\n          env:\n            - name: EXIT_DIR\n              value: \"/var/exitdir\"\n          volumeMounts:\n            - name: exit-dir\n              mountPath: \"/var/exitdir\"\n        - name: follower\n          image: ko://chainguard.dev/exitdir/cmd/follower\n          env:\n            - name: EXIT_DIR\n              value: \"/var/exitdir\"\n          volumeMounts:\n            - name: exit-dir\n              mountPath: \"/var/exitdir\"\n      volumes:\n        - name: exit-dir\n          emptyDir: {}\nEOF\n```\n\nWe can see the job finished:\n\n```shell\n% kubectl get job\nNAME      COMPLETIONS   DURATION   AGE\nexample   1/1           8s         17s\n```\n\nAnd finding the pod, we can view the logs of each container:\n\n```shell\n$ kubectl logs example-78fm7 leader\n[Leader] Doing work...\n[Leader] Exiting...\n```\n\n```shell\n$  kubectl logs example-78fm7 follower\n[Follower] Tick 0\n[Follower] Tick 1\n[Follower] Tick 2\n[Follower] Tick 3\n[Follower] Exiting...\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchainguard-dev%2Fexitdir","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchainguard-dev%2Fexitdir","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchainguard-dev%2Fexitdir/lists"}