]> git.openstreetmap.org Git - chef.git/commitdiff
Add a small preload library to flush files on close
authorTom Hughes <tom@compton.nu>
Wed, 7 Sep 2016 10:22:38 +0000 (11:22 +0100)
committerTom Hughes <tom@compton.nu>
Wed, 7 Sep 2016 10:23:35 +0000 (11:23 +0100)
cookbooks/planet/files/default/flush/Makefile [new file with mode: 0644]
cookbooks/planet/files/default/flush/flush.c [new file with mode: 0644]
cookbooks/planet/recipes/replication.rb

diff --git a/cookbooks/planet/files/default/flush/Makefile b/cookbooks/planet/files/default/flush/Makefile
new file mode 100644 (file)
index 0000000..b42035e
--- /dev/null
@@ -0,0 +1,2 @@
+flush.so: flush.c
+       cc -O2 -fPIC -D_GNU_SOURCE -shared -o flush.so flush.c -ldl
diff --git a/cookbooks/planet/files/default/flush/flush.c b/cookbooks/planet/files/default/flush/flush.c
new file mode 100644 (file)
index 0000000..c80e86a
--- /dev/null
@@ -0,0 +1,16 @@
+#include <dlfcn.h>
+#include <unistd.h>
+
+static int (*real_close)(int fd);
+
+static void __attribute__((constructor)) initialise(void)
+{
+  real_close = dlsym(RTLD_NEXT, "close");
+}
+
+int close(int fd)
+{
+  fdatasync(fd);
+
+  return real_close(fd);
+}
index d9ff9b67c04cfae7bb0dba9d47482b16f71cef22..25fe9671da5e4e186293a2cf8a35df600c677358 100644 (file)
@@ -30,6 +30,28 @@ package "ruby-libxml"
 package "libpq-dev"
 gem_package "pg"
 
+package "make"
+package "gcc"
+
+remote_directory "/opt/flush" do
+  source "flush"
+  owner "root"
+  group "root"
+  mode 0o755
+  files_owner "root"
+  files_group "root"
+  files_mode 0o755
+end
+
+execute "/opt/flush/Makefile" do
+  action :nothing
+  command "make"
+  cwd "/opt/flush"
+  user "root"
+  group "root"
+  subscribes :run, "remote_directory[/opt/flush]"
+end
+
 remote_directory "/usr/local/bin" do
   source "replication-bin"
   owner "root"