Skip to content

Instantly share code, notes, and snippets.

@tubit
Created July 23, 2013 22:50
Show Gist options
  • Save tubit/6066850 to your computer and use it in GitHub Desktop.
Save tubit/6066850 to your computer and use it in GitHub Desktop.
Create file lock on file to prevent concurrent script runs.
#!/usr/bin/env ruby
DATA.flock(File::LOCK_EX | File::LOCK_NB) or abort "Already running."
trap("INT", "EXIT")
puts "Running..."
loop do
sleep
end
__END__
DO NOT DELETE: used for locking
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment