]> git.immae.eu Git - perso/Immae/Config/Nix.git/commitdiff
Add phpFpm prestart script to lib
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Sat, 1 Jun 2019 10:22:13 +0000 (12:22 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Sat, 1 Jun 2019 10:22:13 +0000 (12:22 +0200)
lib/private/default.nix
modules/private/websites/aten/builder.nix
modules/private/websites/connexionswing/builder.nix
modules/private/websites/florian/builder_app.nix
modules/private/websites/ludivinecassal/builder.nix
modules/private/websites/piedsjaloux/builder.nix
modules/private/websites/tools/tools/wallabag.nix

index c7d753a30e8ffb7542ef905d0b23abc167c71a38..b04f7b3902b1bf1556a98e5acb6334b7e843dbb3 100644 (file)
       echo
     }
   '';
+
+  phpFpmPreStart = { app, varDir, keyFiles, actions }: ''
+    if [ ! -f "${varDir}/currentWebappDir" -o \
+        ! -f "${varDir}/currentKey" -o \
+        "${app}" != "$(cat ${varDir}/currentWebappDir 2>/dev/null)" ] \
+        || ! sha512sum -c --status ${varDir}/currentKey; then
+      pushd ${app} > /dev/null
+      ${builtins.concatStringsSep "\n  " actions}
+      popd > /dev/null
+      echo -n "${app}" > ${varDir}/currentWebappDir
+      sha512sum ${builtins.concatStringsSep " " keyFiles} > ${varDir}/currentKey
+    fi
+  '';
 }
index 9a2e1a7de24709054f410b8d0f538335cd0d0238..83a8f700fcf3b140e4c81deb2dd09aea81b85896 100644 (file)
@@ -1,18 +1,16 @@
-{ apacheUser, apacheGroup, aten, lib, config }: rec {
+{ apacheUser, apacheGroup, aten, lib, mylibs, config }: rec {
   app = aten.override { inherit (config) environment; };
   phpFpm = rec {
-    preStart = ''
-      if [ ! -f "${app.varDir}/currentWebappDir" -o \
-          ! -f "${app.varDir}/currentKey" -o \
-          "${app}" != "$(cat ${app.varDir}/currentWebappDir 2>/dev/null)" ] \
-          || ! sha512sum -c --status ${app.varDir}/currentKey; then
-        pushd ${app} > /dev/null
-        /run/wrappers/bin/sudo -u ${apacheUser} APP_ENV=${app.environment} ./bin/console --env=${app.environment} cache:clear --no-warmup
-        popd > /dev/null
-        echo -n "${app}" > ${app.varDir}/currentWebappDir
-        sha512sum /var/secrets/webapps/${app.environment}-aten > ${app.varDir}/currentKey
-      fi
-      '';
+    preStart = mylibs.phpFpmPreStart {
+      inherit app;
+      inherit (app) varDir;
+      keyFiles = [
+        "/var/secrets/webapps/${app.environment}-aten"
+      ];
+      actions = [
+        "/run/wrappers/bin/sudo -u ${apacheUser} APP_ENV=${app.environment} ./bin/console --env=${app.environment} cache:clear --no-warmup"
+      ];
+    };
     serviceDeps = [ "postgresql.service" ];
     socket = "/var/run/phpfpm/aten-${app.environment}.sock";
     pool = ''
index b4b04cb2275a54c87254d2cd96344601e38a5a6f..004b9796ccff210b6cd81d491a984ee51d7871bf 100644 (file)
@@ -1,4 +1,4 @@
-{ apacheUser, apacheGroup, connexionswing, pkgs, phpPackages, config }:
+{ apacheUser, apacheGroup, connexionswing, pkgs, phpPackages, mylibs, config }:
 rec {
   app = connexionswing.override { inherit (config) environment; };
   keys = [{
@@ -31,18 +31,16 @@ rec {
     '';
   }];
   phpFpm = rec {
-    preStart = ''
-      if [ ! -f "${app.varDir}/currentWebappDir" -o \
-          ! -f "${app.varDir}/currentKey" -o \
-          "${app}" != "$(cat ${app.varDir}/currentWebappDir 2>/dev/null)" ] \
-          || ! sha512sum -c --status ${app.varDir}/currentKey; then
-        pushd ${app} > /dev/null
-        /run/wrappers/bin/sudo -u ${apacheUser} ./bin/console --env=${app.environment} cache:clear --no-warmup
-        popd > /dev/null
-        echo -n "${app}" > ${app.varDir}/currentWebappDir
-        sha512sum /var/secrets/webapps/${app.environment}-connexionswing > ${app.varDir}/currentKey
-      fi
-      '';
+    preStart = mylibs.phpFpmPreStart {
+      inherit app;
+      inherit (app) varDir;
+      keyFiles = [
+        "/var/secrets/webapps/${app.environment}-connexionswing"
+      ];
+      actions = [
+        "/run/wrappers/bin/sudo -u ${apacheUser} ./bin/console --env=${app.environment} cache:clear --no-warmup"
+      ];
+    };
     serviceDeps = [ "mysql.service" ];
     socket = "/var/run/phpfpm/connexionswing-${app.environment}.sock";
     phpConfig = ''
index e521f6ebfe6e8d2b7c6df46a1e97c8177af2c1b1..c12663a7175e4fd09ff76f8e4886c885723926e9 100644 (file)
@@ -1,4 +1,4 @@
-{ apacheUser, apacheGroup, tellesflorian, config }:
+{ apacheUser, apacheGroup, tellesflorian, mylibs, config }:
 rec {
   app = tellesflorian.override { inherit (config) environment; };
   keys = [
@@ -33,18 +33,16 @@ rec {
     }
   ];
   phpFpm = rec {
-    preStart = ''
-      if [ ! -f "${app.varDir}/currentWebappDir" -o \
-          ! -f "${app.varDir}/currentKey" -o \
-          "${app}" != "$(cat ${app.varDir}/currentWebappDir 2>/dev/null)" ] \
-          || ! sha512sum -c --status ${app.varDir}/currentKey; then
-        pushd ${app} > /dev/null
-        /run/wrappers/bin/sudo -u wwwrun ./bin/console --env=${app.environment} cache:clear --no-warmup
-        popd > /dev/null
-        echo -n "${app}" > ${app.varDir}/currentWebappDir
-        sha512sum /var/secrets/webapps/${app.environment}-tellesflorian > ${app.varDir}/currentKey
-      fi
-      '';
+    preStart = mylibs.phpFpmPreStart {
+      inherit app;
+      inherit (app) varDir;
+      keyFiles = [
+        "/var/secrets/webapps/${app.environment}-tellesflorian"
+      ];
+      actions = [
+        "/run/wrappers/bin/sudo -u wwwrun ./bin/console --env=${app.environment} cache:clear --no-warmup"
+      ];
+    };
     serviceDeps = [ "mysql.service" ];
     socket = "/var/run/phpfpm/floriantelles-${app.environment}.sock";
     pool = ''
index 3167bce7358ad7da61a54ea8935be233abc01d2c..e2a0f190c7bae1ac975250420037550373141153 100644 (file)
@@ -1,4 +1,4 @@
-{ apacheUser, apacheGroup, config, ludivinecassal, pkgs, ruby, sass, imagemagick }:
+{ apacheUser, apacheGroup, config, ludivinecassal, mylibs, pkgs, ruby, sass, imagemagick }:
 rec {
   app = ludivinecassal.override { inherit (config) environment; };
   varDir = "/var/lib/ludivinecassal_${app.environment}";
@@ -39,18 +39,16 @@ rec {
     '';
   }];
   phpFpm = rec {
-    preStart = ''
-      if [ ! -f "${app.varDir}/currentWebappDir" -o \
-          ! -f "${app.varDir}/currentKey" -o \
-          "${app}" != "$(cat ${app.varDir}/currentWebappDir 2>/dev/null)" ] \
-          || ! sha512sum -c --status ${app.varDir}/currentKey; then
-        pushd ${app} > /dev/null
-        /run/wrappers/bin/sudo -u ${apacheUser} ./bin/console --env=${app.environment} cache:clear --no-warmup
-        popd > /dev/null
-        echo -n "${app}" > ${app.varDir}/currentWebappDir
-        sha512sum /var/secrets/webapps/${app.environment}-ludivinecassal > ${app.varDir}/currentKey
-      fi
-      '';
+    preStart = mylibs.phpFpmPreStart {
+      inherit app;
+      inherit (app) varDir;
+      keyFiles = [
+        "/var/secrets/webapps/${app.environment}-ludivinecassal"
+      ];
+      actions = [
+        "/run/wrappers/bin/sudo -u ${apacheUser} ./bin/console --env=${app.environment} cache:clear --no-warmup"
+      ];
+    };
     serviceDeps = [ "mysql.service" ];
     socket = "/var/run/phpfpm/ludivinecassal-${app.environment}.sock";
     pool = ''
index 9fcc8fb684b914ccdd362a22c114315cfb6b24b1..d9a78b3b7e64e3221c0582432d1df388cfa20131 100644 (file)
@@ -1,4 +1,4 @@
-{ apacheUser, apacheGroup, piedsjaloux, config, pkgs, lib, texlive, imagemagick }:
+{ apacheUser, apacheGroup, piedsjaloux, config, pkgs, lib, mylibs, texlive, imagemagick }:
 rec {
   app = piedsjaloux.override { inherit (config) environment; };
   varDir = "/var/lib/piedsjaloux_${app.environment}";
@@ -27,18 +27,16 @@ rec {
     '';
   }];
   phpFpm = rec {
-    preStart = ''
-      if [ ! -f "${app.varDir}/currentWebappDir" -o \
-          ! -f "${app.varDir}/currentKey" -o \
-          "${app}" != "$(cat ${app.varDir}/currentWebappDir 2>/dev/null)" ] \
-          || ! sha512sum -c --status ${app.varDir}/currentKey; then
-        pushd ${app} > /dev/null
-        /run/wrappers/bin/sudo -u ${apacheUser} ./bin/console --env=${app.environment} cache:clear --no-warmup
-        popd > /dev/null
-        echo -n "${app}" > ${app.varDir}/currentWebappDir
-        sha512sum /var/secrets/webapps/${app.environment}-piedsjaloux > ${app.varDir}/currentKey
-      fi
-      '';
+    preStart = mylibs.phpFpmPreStart {
+      inherit app;
+      inherit (app) varDir;
+      keyFiles = [
+        "/var/secrets/webapps/${app.environment}-piedsjaloux"
+      ];
+      actions = [
+        "/run/wrappers/bin/sudo -u ${apacheUser} ./bin/console --env=${app.environment} cache:clear --no-warmup"
+      ];
+    };
     serviceDeps = [ "mysql.service" ];
     socket = "/var/run/phpfpm/piedsjaloux-${app.environment}.sock";
     pool = ''
index d6e588285e19eaa4159d633237d04afdcca439ac..ba755e4d514fbc3636960f0f0e906f138a528e8c 100644 (file)
@@ -1,4 +1,4 @@
-{ env, wallabag }:
+{ env, wallabag, mylibs }:
 rec {
   varDir = "/var/lib/wallabag";
   keys = [{
@@ -110,20 +110,18 @@ rec {
       '';
   };
   phpFpm = rec {
-    preStart = ''
-      if [ ! -f "${varDir}/currentWebappDir" -o \
-          ! -f "${varDir}/currentKey" -o \
-          "${webappDir}" != "$(cat ${varDir}/currentWebappDir 2>/dev/null)" ] \
-          || ! sha512sum -c --status ${varDir}/currentKey; then
-        pushd ${webappDir} > /dev/null
-        /run/wrappers/bin/sudo -u wwwrun ./bin/console --env=prod cache:clear
-        rm -rf /var/lib/wallabag/var/cache/pro_
-        /run/wrappers/bin/sudo -u wwwrun ./bin/console --env=prod doctrine:migrations:migrate --no-interaction
-        popd > /dev/null
-        echo -n "${webappDir}" > ${varDir}/currentWebappDir
-        sha512sum /var/secrets/webapps/tools-wallabag > ${varDir}/currentKey
-      fi
-      '';
+    preStart = mylibs.phpFpmPreStart {
+      app = webappDir;
+      inherit varDir;
+      keyFiles = [
+        "/var/secrets/webapps/tools-wallabag"
+      ];
+      actions = [
+        "/run/wrappers/bin/sudo -u wwwrun ./bin/console --env=prod cache:clear"
+        "rm -rf /var/lib/wallabag/var/cache/pro_"
+        "/run/wrappers/bin/sudo -u wwwrun ./bin/console --env=prod doctrine:migrations:migrate --no-interaction"
+      ];
+    };
     serviceDeps = [ "postgresql.service" "openldap.service" ];
     basedir = builtins.concatStringsSep ":" [ webappDir "/var/secrets/webapps/tools-wallabag" varDir ];
     socket = "/var/run/phpfpm/wallabag.sock";