Skip to content

Simple CLI integration #36

Description

@splitice

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.

Activity

  1. changed the title [-]Simple integration options[/-] [+]Simple CLI integration[/+] on Sep 30, 2021
  2. distorhead commented on Oct 4, 2021

    @distorhead
    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).

  3. splitice commented on Oct 4, 2021

    @splitice
    Author

    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 👍

  4. cwarden commented on May 17, 2024

    @cwarden
    Contributor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions