{"id":19168395,"url":"https://github.com/bloomberg/locking_resource-cookbook","last_synced_at":"2025-08-09T09:31:54.661Z","repository":{"id":54156869,"uuid":"75119194","full_name":"bloomberg/locking_resource-cookbook","owner":"bloomberg","description":"Chef cookbook for serializing access to resources","archived":false,"fork":false,"pushed_at":"2019-06-27T21:21:08.000Z","size":77,"stargazers_count":7,"open_issues_count":3,"forks_count":9,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-04-19T23:31:58.571Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","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/bloomberg.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":"2016-11-29T20:29:15.000Z","updated_at":"2022-05-07T07:40:58.000Z","dependencies_parsed_at":"2022-08-13T07:50:44.744Z","dependency_job_id":null,"html_url":"https://github.com/bloomberg/locking_resource-cookbook","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/bloomberg%2Flocking_resource-cookbook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bloomberg%2Flocking_resource-cookbook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bloomberg%2Flocking_resource-cookbook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bloomberg%2Flocking_resource-cookbook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bloomberg","download_url":"https://codeload.github.com/bloomberg/locking_resource-cookbook/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252897414,"owners_count":21821433,"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-09T09:42:30.664Z","updated_at":"2025-05-07T14:41:47.846Z","avatar_url":"https://github.com/bloomberg.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Description\nThe locking resource cookbook provides resources to lock various other Chef resources. This can be used to  prevent a distributed environment from having multiple machines simultaneously executing a particular resource. \n\nUse cases envisioned:\n* Prevent stampeding herds knocking over a particularly fragile end-point by serializing access\n* Prevent all instances of a service going down en mass during configuration updates\n* Communicate state if a particular service is not coming back up (preventing a toxic-configuration from causing cascading failures) and still verifying if a process is restarted outside of Chef using process start time.\n\n## Requirements\nThe Zookeeper gem and a Zookeeper cluster is required. While envisioned to use a generic synchronous state engineer, today Zookeeper is used for all lock coordination.\n\n## Attributes\n* `node[:locking_resource][:restart_lock][:root]` - Zookeeper namespace under which all locks are created\n* `node[:locking_resource][:restart_lock_acquire][:sleep_time]` - Sleep time in (fractions-of) seconds between tries to acquire a lock for restart\n* `node[:locking_resource][:restart_lock_acquire][:timeout]` - Timeout in seconds before failing to acquire lock\n* `node[:locking_resource][:skip_restart_coordination]` - Flag to skip attempting lock coordination (will just assume lock was acquired and not block)\n* `node[:locking_resource][:zookeeper_servers]` - The default zookeeper quorum\n\n## Resources\n* `locking_resource` - The HWRP for achieving locking\n\n### Actions\n* `:serialize` - Will run the requested action every Chef run as long as a lock can be acquired \n* `:serialize_process` - Is like `:serialize` except that should it leave a stale lock, it also verifies if the specified process has restarted since the lock was acquired and if so, cleans-up the lock not restarting again\n\n#### `:serialize`\nWill run the requested action every Chef run as long as a lock can be acquired \n\n##### Relevant Attributes\n* `:resource` - String name of resource to control (uses the same `'resource[name]'` syntax as `:notifies`/`:subscribes`)\n* `:perform` - Action to perform on `:resource` when called (locked resources are often set to `:nothing` to avoid running outside of lock)\n* `:timeout` - Optional timeout override for resources which might hold a lock particularly long\n* `:lock_data` - Optional data to put in lock; (envisioned to provide ability to lock on a topology grouping e.g. a rack)\n\n#### `:serialize_process`\nWill run the requested action every Chef run as long as a lock can be acquired; provides extra features for a process affecting resource. Will verify that if the machine is found to be holding a stale lock and the process as restarted since the lock was taken out, the lock will be released with no action. This provides an ability for a service to fail restarting (e.g. due to an exogenous resource failure; like a disk), to take out a lock to prevent other like processes going down electively and to be cleared by an administrator (e.g. disk replaced) and for Chef to clear the condition automatically.\n\n* `:process_pattern` - Takes a block of options to define the process to keep an eye on:\n * `full_cmd` - Boolean as to if `ps(1)` should use `-ww` and read the contents of `cmd` for a full command string search (otherwise it reads the contents of `comm`)\n * `command_string` - The process string to search for (e.g. `java`)\n * `user` - The numeric UID or ASCII username string of the user running the process\n * Only `user` or `command_string` need be supplied (both may be)\n\nContributing\n============\nContributions are welcomed! This cookbook tries to have rigorous testing to verify that locks are held and released as expected. The current process for kicking these off on a machine with ChefDK is:\n````\n$ export PATH=/opt/chefdk/embedded/bin:$PATH\n$ bundler package --path=vendor/cache\n$ berks vendor\n$ bundler exec rspec\n$ kitchen converge '.*'\n````\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbloomberg%2Flocking_resource-cookbook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbloomberg%2Flocking_resource-cookbook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbloomberg%2Flocking_resource-cookbook/lists"}