Skip to content

Add locking in the primary r10k binary. This serializes runs of r10k … #610

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions bin/r10k
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@

require 'r10k/cli'
require 'colored'
lockfile = "/tmp/r10k.lock"

begin
R10K::CLI.command.run(ARGV)
rescue Interrupt
$stderr.puts "Aborted!".red
exit(1)
rescue SystemExit => e
exit(e.status)
rescue Exception => e
$stderr.puts "\nError while running: #{e.inspect}".red
$stderr.puts e.backtrace.join("\n").red if ARGV.include? '--trace'
exit(1)
File.open(lockfile, File::RDWR|File::CREAT, 0644) do |f|
f.flock(File::LOCK_EX)
begin
R10K::CLI.command.run(ARGV)
rescue Interrupt
$stderr.puts "Aborted!".red
exit(1)
rescue SystemExit => e
exit(e.status)
rescue Exception => e
$stderr.puts "\nError while running: #{e.inspect}".red
$stderr.puts e.backtrace.join("\n").red if ARGV.include? '--trace'
exit(1)
end
end