Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple CLI integration #36

Open
splitice opened this issue Sep 30, 2021 · 3 comments
Open

Simple CLI integration #36

splitice opened this issue Sep 30, 2021 · 3 comments

Comments

@splitice
Copy link

splitice commented Sep 30, 2021

Thank you for your hard work. Been reading through this and the few other implementations of distributed locking systems. A uniquely simple design in this case. Effectively you take the lock for (default) 10 seconds and keep renewing it preventing expiration (every 3 seconds). Simple design and K8S services while they can be a bit jittery should be reliable on that scale. Competition between acquiring workers being handled by a race to insert.

I don't do anything normally with golang so correct me if I am wrong.

Any chance that an (example?) of a CLI application could be developed that could be usable from scripting languages? This would make your work accessible from sh/bash (or any other scripting language supporting shell commands - i.e most of them)? I suspect even languages like PHP and python could make use of it via proc open type interfaces.

My thoughts regarding API:

#!/bin/bash

keyname="our key"

# take lock $keyname
k8lock $keyname &
lockpid=$!

do_stuff

# signal for clean exit
kill -sHUP $lockpid
wait $lockpid

distlock should also monitor it's parent pid for exit (and release the lock accordingly i.e in case of crash).

In C I would do this with a signal handler on SIGHUP and use PR_SET_PDEATHSIG to ensure a SIGHUP is received on parent death for that graceful cleanup.

@splitice splitice changed the title Simple integration options Simple CLI integration Sep 30, 2021
@distorhead
Copy link
Member

Hi, thanks for your feedback!

I think it would be great to implement such CLI app. Flock unix util could be used as another example CLI.

The only thing: it is important to implement on-lost-lease handler for such CLI command, in the simple/universal case this handler should just crash whole script immediately, in some cases this handler could revert back introduced changes then crash (depends on an application logic).

@splitice
Copy link
Author

splitice commented Oct 4, 2021

I guess if the lock cli exits early thats a lost lock. Although that really shouldnt be possible and many CLI applications are not easily able to check the statuses of their children (and shouldnt be expected to). I don't think the child sending signals to the parent is a good idea (e.g to interrupt / terminate it) at-least not by default.

I'm pretty much thinking of usage like a simple distributed flock 👍

@cwarden
Copy link
Contributor

cwarden commented May 17, 2024

Here's a simple cli I built using lockgate: https://github.com/octoberswimmer/deploylock

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants