diff options
author | Steve Kemp <steve@steve.org.uk> | 2015-08-13 12:58:36 +0300 |
---|---|---|
committer | Steve Kemp <steve@steve.org.uk> | 2015-08-13 12:58:36 +0300 |
commit | a202827d441c3afe2ed81da32593ed2f7397228b (patch) | |
tree | aae5d5d528d00cbc1d59bbae0c16f71a94b01c29 | |
parent | 0fc32727474ed8f072a1692bb0e91178b2a6c663 (diff) |
Abort cleanly if we cannot acquire our lockfile.
This avoids a backtrace, and shows a clean reason for failure.
-rw-r--r-- | lib/byteback/util.rb | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/byteback/util.rb b/lib/byteback/util.rb index 99a5b23..9a993d6 100644 --- a/lib/byteback/util.rb +++ b/lib/byteback/util.rb @@ -35,8 +35,12 @@ module Byteback end # Own the pidfile ourselves - File.open(@@lockfile, 'w') do |lockfile| - lockfile.puts Process.pid + begin + File.open(@@lockfile, 'w') do |lockfile| + lockfile.puts Process.pid + end + rescue => _ex + fatal("Failed to open lockfile - are you running as root?") end end |