Use trap to release lock
[chef.git] / cookbooks / planet / templates / default / planetdump.erb
index 068ce5d5fd09d0f0d85d14ac1cd1311af506382c..4d5bac02ce64c61e90de2214ab8a8f828b3dfb1e 100644 (file)
@@ -26,6 +26,14 @@ fi
 # Create Lock
 echo $$ > /tmp/planetdump.lock
 
+function cleanup {
+        # Release lock
+        rm /tmp/planetdump.lock
+}
+
+# Remove lock on exit
+trap cleanup EXIT
+
 # Change to working directory
 cd /store/planetdump
 
@@ -56,6 +64,3 @@ do
     md5sum "#{file}" > "#{file}.md5"
     mv "${file}" "${file}.md5" "/store/planet/pbf"
 done
-
-# Release lock
-rm /tmp/planetdump.lock