An open API service indexing awesome lists of open source software.

https://github.com/oresoftware/quicklock

Create a simple one-line mutex, useful for shell scripts.
https://github.com/oresoftware/quicklock

bash lock lockfile mutex scripting shell

Last synced: 6 months ago
JSON representation

Create a simple one-line mutex, useful for shell scripts.

Awesome Lists containing this project

README

          

## QuickLock

******************************************************************************************

##### install: `$ curl -o- https://raw.githubusercontent.com/oresoftware/quicklock/master/install.sh | bash`

or

##### install: `$ wget -q -O - https://raw.githubusercontent.com/oresoftware/quicklock/master/install.sh | bash`

******************************************************************************************

## Simple usage

```bash
#!/usr/bin/env bash

# acquire lock. will exit with exit code 1, if lock cannot be acquired the first time
# first and only argument is an optional lockname, if no argument is passed, $PWD will be used as a good default.

ql_acquire_lock "$PWD"

# your critical code goes here

foobarbaz --watch # this can be whatever you want

# when the script/process exits, lock will automatically be released

```

*******************************************************************************************

### Explicit unlocking

For most use cases you don't need to explicitly unlock.

```bash
#!/usr/bin/env bash

ql_acquire_lock "$PWD"

# your critical code goes here
echo "foo bar bar"

# we can release the lock here if we want and continue with more commands

ql_release_lock # lockname is an optional argument

# we released the lock, because we are done with the critical section
# now we can run whatever

dosomethingelse here

```
*****************************************************************************

## Debugging

To get a list of all the quicklock locks that exist, use:

`$ ql_ls`

To determine which process holds a lock, use:

`$ ql_find # lockname is optional`

`ql_find` echos a pid, if the lock exists. To find out information about that pid, you can use:

`$ ps -p `

or just do this:

`$ ql_find | xargs ps -p`

******************************************************************************

### Colors

Terminal colors/styling is on by default.

To turn off color use:

`$ ql_no_color`

to turn colors back on, use:

`$ ql_add_color`