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.
- Host: GitHub
- URL: https://github.com/oresoftware/quicklock
- Owner: ORESoftware
- Created: 2018-02-28T06:27:54.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-05-30T02:58:08.000Z (over 7 years ago)
- Last Synced: 2024-10-07T18:47:59.509Z (about 1 year ago)
- Topics: bash, lock, lockfile, mutex, scripting, shell
- Language: JavaScript
- Homepage:
- Size: 226 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
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 bashql_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 whateverdosomethingelse 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`