Posted almost 3 years ago. Visible to the public. Repeats. Linked content.

Linux: Running a single unique instance of command + arguments

run-one is a wrapper script that won't run the given command while another instance of it is running. Is brings several utility commands that offer similar behavior.

NAME run-one - run just one instance at a time of some command and unique set of arguments (useful for cronjobs, eg) SYNOPSIS run-one COMMAND [ARGS] run-this-one COMMAND [ARGS] run-one-constantly COMMAND [ARGS] keep-one-running COMMAND [ARGS] run-one-until-success COMMAND [ARGS] run-one-until-failure COMMAND [ARGS] DESCRIPTION run-one is a wrapper script that runs no more than one unique instance of some command with a unique set of arguments. This is often useful with cronjobs, when you want no more than one copy running at a time. run-this-one is exactly like run-one, except that it will use pgrep(1) and kill(1) to find and kill any running processes owned by the user and matching the target commands and arguments. Note that run-this-one will block while trying to kill matching processes, until all matching processes are dead. run-one-constantly operates exactly like run-one except that it respawns "COMMAND [ARGS]" any time COMMAND exits (zero or non-zero). keep-one-running is an alias for run-one-constantly. run-one-until-success operates exactly like run-one-constantly except that it respawns "COMMAND [ARGS]" until COMMAND exits successfully (ie, exits zero). run-one-until-failure operates exactly like run-one-constantly except that it respawns "COMMAND [ARGS]" until COMMAND exits with failure (ie, exits non-zero).

Internally, it hashes command+arguments and flocks on the hash.

Once an application no longer requires constant development, it needs periodic maintenance for stable and secure operation. makandra offers monthly maintenance contracts that let you focus on your business while we make sure the lights stay on.

Owner of this card:

Dominik Schöler
Last edit:
6 months ago
by Besprechungs-PC
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Dominik Schöler to makandra dev
This website uses cookies to improve usability and analyze traffic.
Accept or learn more