From 4360f70d7a9966593d9e04043fa0a75defc094e0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Isma=C3=ABl=20Bouya?= Date: Sat, 1 Jun 2019 12:22:13 +0200 Subject: [PATCH] Add phpFpm prestart script to lib --- lib/private/default.nix | 13 +++++++++ modules/private/websites/aten/builder.nix | 24 ++++++++-------- .../websites/connexionswing/builder.nix | 24 ++++++++-------- .../private/websites/florian/builder_app.nix | 24 ++++++++-------- .../websites/ludivinecassal/builder.nix | 24 ++++++++-------- .../private/websites/piedsjaloux/builder.nix | 24 ++++++++-------- .../private/websites/tools/tools/wallabag.nix | 28 +++++++++---------- 7 files changed, 81 insertions(+), 80 deletions(-) diff --git a/lib/private/default.nix b/lib/private/default.nix index c7d753a..b04f7b3 100644 --- a/lib/private/default.nix +++ b/lib/private/default.nix @@ -17,4 +17,17 @@ 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 + ''; } diff --git a/modules/private/websites/aten/builder.nix b/modules/private/websites/aten/builder.nix index 9a2e1a7..83a8f70 100644 --- a/modules/private/websites/aten/builder.nix +++ b/modules/private/websites/aten/builder.nix @@ -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 = '' diff --git a/modules/private/websites/connexionswing/builder.nix b/modules/private/websites/connexionswing/builder.nix index b4b04cb..004b979 100644 --- a/modules/private/websites/connexionswing/builder.nix +++ b/modules/private/websites/connexionswing/builder.nix @@ -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 = '' diff --git a/modules/private/websites/florian/builder_app.nix b/modules/private/websites/florian/builder_app.nix index e521f6e..c12663a 100644 --- a/modules/private/websites/florian/builder_app.nix +++ b/modules/private/websites/florian/builder_app.nix @@ -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 = '' diff --git a/modules/private/websites/ludivinecassal/builder.nix b/modules/private/websites/ludivinecassal/builder.nix index 3167bce..e2a0f19 100644 --- a/modules/private/websites/ludivinecassal/builder.nix +++ b/modules/private/websites/ludivinecassal/builder.nix @@ -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 = '' diff --git a/modules/private/websites/piedsjaloux/builder.nix b/modules/private/websites/piedsjaloux/builder.nix index 9fcc8fb..d9a78b3 100644 --- a/modules/private/websites/piedsjaloux/builder.nix +++ b/modules/private/websites/piedsjaloux/builder.nix @@ -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 = '' diff --git a/modules/private/websites/tools/tools/wallabag.nix b/modules/private/websites/tools/tools/wallabag.nix index d6e5882..ba755e4 100644 --- a/modules/private/websites/tools/tools/wallabag.nix +++ b/modules/private/websites/tools/tools/wallabag.nix @@ -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"; -- 2.41.0