Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/krezreb/singleton
Easily run scripts in singleton mode, no race conditions
https://github.com/krezreb/singleton
bash locks
Last synced: 10 days ago
JSON representation
Easily run scripts in singleton mode, no race conditions
- Host: GitHub
- URL: https://github.com/krezreb/singleton
- Owner: krezreb
- Created: 2020-02-19T09:49:03.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-02-19T13:59:22.000Z (over 4 years ago)
- Last Synced: 2024-02-14T21:55:28.956Z (9 months ago)
- Topics: bash, locks
- Language: Shell
- Homepage:
- Size: 4.88 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# singleton
Easily run scripts in singleton mode, e.g.: only one instance can be running on the system at a time. Uses atomic file locks, so there's no race conditions.
## Installation
Once you've cloned this repo
`sudo make install`
Installs in /usr/bin
Or install with this one liner
```
sudo wget https://raw.githubusercontent.com/krezreb/singleton/master/singleton.sh -O /usr/bin/singleton \
&& sudo chmod +x /usr/bin/singleton
```## Usage
`singleton LOCKNAME PROGRAM ARGS...`
Can also be used in your own scripts
```
#!/bin/env bash$(singleton source) # gives you lock_try and lock_release functions
if lock_try LOCKNAME ; then
# do stuff here
lock_release
else
# lock failed
fi
```Examples:
Using singleton can be as easy as prepending "singleton LOCKNAME" to any command, here is a long running rsync command whose lock is called "backup"
```
singleton backup rsync -arv a b
```## Running Tests
`make test`
Runs a bunch of parallel test programs, only one winner of which should get the lock.