Skip to content

Easily run scripts in singleton mode, no race conditions

Notifications You must be signed in to change notification settings

krezreb/singleton

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Easily run scripts in singleton mode, no race conditions

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published