]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - modules/private/websites/connexionswing/production.nix
Finish removal of php-application module
[perso/Immae/Config/Nix.git] / modules / private / websites / connexionswing / production.nix
CommitLineData
ab8f306d 1{ lib, pkgs, config, ... }:
f8026b6e 2let
ab8f306d 3 secrets = config.myEnv.websites.connexionswing.production;
f8026b6e 4 cfg = config.myServices.websites.connexionswing.production;
2ff9258e
IB
5 ftpRoot = "/var/lib/connexionswing_production";
6 phpRoot = "${ftpRoot}/php";
7 webRoot = "${phpRoot}/web";
8 varDir = "${ftpRoot}/var";
2ff9258e
IB
9 packagePath = "/var/lib/ftp/release.immae.eu/buildbot/Connexionswing";
10 branch = "master";
f8026b6e
IB
11in {
12 options.myServices.websites.connexionswing.production.enable = lib.mkEnableOption "enable Connexionswing's website in production";
13
14 config = lib.mkIf cfg.enable {
f8026b6e 15 services.webstats.sites = [ { name = "connexionswing.com"; } ];
2ff9258e
IB
16 services.phpfpm.pools.connexionswing_production = {
17 user = config.services.httpd.Prod.user;
18 group = config.services.httpd.Prod.group;
19 settings = {
20 "listen.owner" = config.services.httpd.Prod.user;
21 "listen.group" = config.services.httpd.Prod.group;
22 "php_admin_value[open_basedir]" = builtins.concatStringsSep ":" [
23 ftpRoot
24 config.secrets.fullPaths."websites/connexionswing/production"
25 "/run/wrappers/bin/sendmail"
26 "/tmp"
27 ];
bbea22c0
IB
28 "php_admin_value[session.save_handler]" = "redis";
29 "php_admin_value[session.save_path]" = "'unix:///run/redis-php-sessions/redis.sock?persistent=1&prefix=Connexionswing:Production:'";
5400b9b6
IB
30 "php_admin_value[upload_max_filesize]" = "20M";
31 "php_admin_value[post_max_size]" = "20M";
32 #"php_admin_flag[log_errors]" = "on";
33 "pm" = "dynamic";
34 "pm.max_children" = "20";
35 "pm.start_servers" = "2";
36 "pm.min_spare_servers" = "1";
37 "pm.max_spare_servers" = "3";
38 };
bbea22c0 39 phpPackage = pkgs.php72.withExtensions ({ enabled, all }: enabled ++ [all.redis]);
f40f5b23 40 };
2ff9258e
IB
41 systemd.services."phpfpm-connexionswing_production" = {
42 after = lib.mkAfter ["mysql.service"];
43 wants = ["mysql.service"];
44 path = lib.mkAfter [ pkgs.gnutar pkgs.gzip pkgs.php72 ];
45 preStart = let
46 script = pkgs.writeScriptBin "connexionswing-production-pre" ''
47 #! ${pkgs.stdenv.shell}
48
49 [ -f ${packagePath}/${branch}.tar.gz ] || exit 1
50
51 cd ${ftpRoot}
52 if ! [ -f .tarball_sum ] || ! sha256sum -c .tarball_sum; then
53 tar -xf ${packagePath}/${branch}.tar.gz --one-top-level=php_new
54 if [ -d php ]; then
55 mv php php_old
56 fi
57 mv php_new php
58 fi
59 cd php
60 rm -rf var/{logs,cache}
61 ln -sf ${varDir}/var/{logs,cache} var/
62 ln -sf ${varDir}/{medias,uploads} web/images/
63 ln -sf ${config.secrets.fullPaths."websites/connexionswing/production"} app/config/parameters.yml
64 SYMFONY_ENV=${secrets.environment} ./bin/console --env=${secrets.environment} cache:clear --no-warmup
65 sha256sum ${packagePath}/${branch}.tar.gz > ${ftpRoot}/.tarball_sum
66 '';
67 in
68 "/run/wrappers/bin/sudo -u ${config.services.httpd.Prod.user} ${script}/bin/connexionswing-production-pre";
69 postStart = let
70 script = pkgs.writeScriptBin "connexionswing-production-post" ''
71 #! ${pkgs.stdenv.shell}
72
73 cd ${ftpRoot}
74 if [ -d php_old ]; then
75 rm -rf php_old
76 fi
77 '';
78 in
79 "/run/wrappers/bin/sudo -u ${config.services.httpd.Prod.user} ${script}/bin/connexionswing-production-post";
80 serviceConfig.TimeoutStartSec="infinity";
81 };
82 services.filesWatcher.phpfpm-connexionswing_production = {
83 restart = true;
84 paths = [ "${packagePath}/${branch}.tar.gz" ];
85 };
86
87 system.activationScripts.connexionswing_production = {
88 deps = ["users"];
89 text = ''
bbea22c0 90 install -m 0700 -o ${config.services.httpd.Prod.user} -g ${config.services.httpd.Prod.group} -d ${ftpRoot}
2ff9258e
IB
91 '';
92 };
8164ed90 93
4c4652aa
IB
94 secrets.keys."websites/connexionswing/production" = {
95 user = config.services.httpd.Prod.user;
96 group = config.services.httpd.Prod.group;
97 permissions = "0400";
98 text = ''
99 # This file is auto-generated during the composer install
100 parameters:
101 database_host: ${secrets.mysql.host}
102 database_port: ${secrets.mysql.port}
103 database_name: ${secrets.mysql.database}
104 database_user: ${secrets.mysql.user}
105 database_password: ${secrets.mysql.password}
e34b3079 106 database_server_version: ${config.myServices.databases.mariadb.package.mysqlVersion}
4c4652aa
IB
107 mailer_transport: sendmail
108 mailer_host: null
109 mailer_user: null
110 mailer_password: null
111 subscription_email: ${secrets.email}
112 allow_robots: true
113 secret: ${secrets.secret}
114 services:
115 swiftmailer.mailer.default.transport:
116 class: Swift_SendmailTransport
117 arguments: ['/run/wrappers/bin/sendmail -bs']
118 '';
119 };
8164ed90 120
d3452fc5 121 services.websites.env.production.vhostConfs.connexionswing_production = {
f8026b6e
IB
122 certName = "connexionswing";
123 certMainHost = "connexionswing.com";
124 hosts = ["connexionswing.com" "sandetludo.com" "www.connexionswing.com" "www.sandetludo.com" ];
2ff9258e 125 root = webRoot;
8164ed90
IB
126 extraConfig = [
127 ''
128 <FilesMatch "\.php$">
2ff9258e 129 SetHandler "proxy:unix:${config.services.phpfpm.pools.connexionswing_production.socket}|fcgi://localhost"
8164ed90
IB
130 </FilesMatch>
131
2ff9258e 132 <Directory ${varDir}/medias>
8164ed90
IB
133 Options FollowSymLinks
134 AllowOverride None
135 Require all granted
136 </Directory>
137
2ff9258e 138 <Directory ${varDir}/uploads>
8164ed90
IB
139 Options FollowSymLinks
140 AllowOverride None
141 Require all granted
142 </Directory>
143
144 Use Stats connexionswing.com
145
2ff9258e 146 <Directory ${webRoot}>
8164ed90
IB
147 Options Indexes FollowSymLinks MultiViews Includes
148 AllowOverride All
149 Require all granted
150 </Directory>
151 ''
152 ];
17f6eae9 153 };
f8026b6e
IB
154 };
155}