X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=modules%2Fprivate%2Fwebsites%2Fconnexionswing%2Fintegration.nix;h=8178d0dd51dbdcee263b4c2f1b9ad5a729d0ebac;hb=2ff9258eb7207efd5c4b80275682a312b2b3022e;hp=93cda002b5b5099095a5f5ebc998f78097fff3e5;hpb=750fe5a43b957b91a26069cf8a4fe19fc7b2633c;p=perso%2FImmae%2FConfig%2FNix.git diff --git a/modules/private/websites/connexionswing/integration.nix b/modules/private/websites/connexionswing/integration.nix index 93cda00..8178d0d 100644 --- a/modules/private/websites/connexionswing/integration.nix +++ b/modules/private/websites/connexionswing/integration.nix @@ -1,51 +1,94 @@ { lib, pkgs, config, ... }: let secrets = config.myEnv.websites.connexionswing.integration; - app = pkgs.callPackage ./app { - composerEnv = pkgs.composerEnv.override { php = pkgs.php72; }; - environment = secrets.environment; - varDir = "/var/lib/connexionswing_integration"; - secretsPath = config.secrets.fullPaths."websites/connexionswing/integration"; - }; cfg = config.myServices.websites.connexionswing.integration; - pcfg = config.services.phpApplication; + ftpRoot = "/var/lib/connexionswing_integration"; + phpRoot = "${ftpRoot}/php"; + webRoot = "${phpRoot}/web"; + varDir = "${ftpRoot}/var"; + sessionDir = "${ftpRoot}/sessions"; + packagePath = "/var/lib/ftp/release.immae.eu/buildbot/Connexionswing"; + branch = "test"; in { options.myServices.websites.connexionswing.integration.enable = lib.mkEnableOption "enable Connexionswing's website in integration"; config = lib.mkIf cfg.enable { - services.duplyBackup.profiles.connexionswing_integration.rootDir = app.varDir; - services.phpApplication.apps.connexionswing_integration = { - websiteEnv = "integration"; - httpdUser = config.services.httpd.Inte.user; - httpdGroup = config.services.httpd.Inte.group; - inherit (app) webRoot varDir; - varDirPaths = { - "medias" = "0700"; - "uploads" = "0700"; - "var" = "0700"; - }; - inherit app; - serviceDeps = [ "mysql.service" ]; - preStartActions = [ - "./bin/console --env=${app.environment} cache:clear --no-warmup" - ]; - phpOpenbasedir = [ "/tmp" "/run/wrappers/bin/sendmail" ]; - phpPool = { + services.phpfpm.pools.connexionswing_integration = { + user = config.services.httpd.Inte.user; + group = config.services.httpd.Inte.group; + settings = { + "listen.owner" = config.services.httpd.Inte.user; + "listen.group" = config.services.httpd.Inte.group; + "php_admin_value[open_basedir]" = builtins.concatStringsSep ":" [ + ftpRoot + config.secrets.fullPaths."websites/connexionswing/integration" + "/tmp" + ]; + "php_admin_value[session.save_path]" = sessionDir; "php_admin_value[upload_max_filesize]" = "20M"; "php_admin_value[post_max_size]" = "20M"; #"php_admin_flag[log_errors]" = "on"; "pm" = "ondemand"; "pm.max_children" = "5"; "pm.process_idle_timeout" = "60"; - }; + }; phpEnv = { SYMFONY_DEBUG_MODE = "\"yes\""; }; - phpWatchFiles = [ - config.secrets.fullPaths."websites/connexionswing/integration" - ]; phpPackage = pkgs.php72; }; + systemd.services."phpfpm-connexionswing_integration" = { + after = lib.mkAfter ["mysql.service"]; + wants = ["mysql.service"]; + path = lib.mkAfter [ pkgs.gnutar pkgs.gzip pkgs.php72 ]; + preStart = let + script = pkgs.writeScriptBin "connexionswing-integration-pre" '' + #! ${pkgs.stdenv.shell} + + [ -f ${packagePath}/${branch}.tar.gz ] || exit 1 + + cd ${ftpRoot} + if ! [ -f .tarball_sum ] || ! sha256sum -c .tarball_sum; then + tar -xf ${packagePath}/${branch}.tar.gz --one-top-level=php_new + if [ -d php ]; then + mv php php_old + fi + mv php_new php + fi + cd php + rm -rf var/{logs,cache} + ln -sf ${varDir}/var/{logs,cache} var/ + ln -sf ${varDir}/{medias,uploads} web/images/ + ln -sf ${config.secrets.fullPaths."websites/connexionswing/integration"} app/config/parameters.yml + SYMFONY_ENV=dev ./bin/console --env=dev cache:clear --no-warmup + sha256sum ${packagePath}/${branch}.tar.gz > ${ftpRoot}/.tarball_sum + ''; + in + "/run/wrappers/bin/sudo -u ${config.services.httpd.Inte.user} ${script}/bin/connexionswing-integration-pre"; + postStart = let + script = pkgs.writeScriptBin "connexionswing-integration-post" '' + #! ${pkgs.stdenv.shell} + + cd ${ftpRoot} + if [ -d php_old ]; then + rm -rf php_old + fi + ''; + in + "/run/wrappers/bin/sudo -u ${config.services.httpd.Inte.user} ${script}/bin/connexionswing-integration-post"; + serviceConfig.TimeoutStartSec="infinity"; + }; + services.filesWatcher.phpfpm-connexionswing_integration = { + restart = true; + paths = [ "${packagePath}/${branch}.tar.gz" ]; + }; + + system.activationScripts.connexionswing_integration = { + deps = ["users"]; + text = '' + install -m 0700 -o ${config.services.httpd.Inte.user} -g ${config.services.httpd.Inte.group} -d ${ftpRoot} ${sessionDir} + ''; + }; secrets.keys."websites/connexionswing/integration" = { user = config.services.httpd.Inte.user; @@ -73,21 +116,21 @@ in { services.websites.env.integration.vhostConfs.connexionswing_integration = { certName = "integration"; addToCerts = true; - hosts = ["connexionswing.immae.eu" "sandetludo.immae.eu" ]; - root = app.webRoot; + hosts = ["connexionswing.cs.immae.dev" "sandetludo.cs.immae.dev" ]; + root = webRoot; extraConfig = [ '' - SetHandler "proxy:unix:${pcfg.phpListenPaths.connexionswing_integration}|fcgi://localhost" + SetHandler "proxy:unix:${config.services.phpfpm.pools.connexionswing_integration.socket}|fcgi://localhost" - + Options FollowSymLinks AllowOverride None Require all granted - + Options FollowSymLinks AllowOverride None Require all granted @@ -95,11 +138,11 @@ in { Use LDAPConnect - Require ldap-group cn=connexionswing.immae.eu,cn=httpd,ou=services,dc=immae,dc=eu + Require ldap-group cn=cs.immae.dev,cn=httpd,ou=services,dc=immae,dc=eu ErrorDocument 401 "" - + Options Indexes FollowSymLinks MultiViews Includes AllowOverride None Require all granted