]>
Commit | Line | Data |
---|---|---|
ab8f306d | 1 | { lib, pkgs, config, ... }: |
f8026b6e | 2 | let |
ab8f306d | 3 | secrets = config.myEnv.websites.piedsjaloux.production; |
f8026b6e | 4 | cfg = config.myServices.websites.piedsjaloux.production; |
d3452fc5 | 5 | texlive = pkgs.texlive.combine { inherit (pkgs.texlive) attachfile preprint scheme-small; }; |
2ff9258e IB |
6 | ftpRoot = "/var/lib/piedsjaloux_production"; |
7 | phpRoot = "${ftpRoot}/php"; | |
8 | webRoot = "${phpRoot}/web"; | |
9 | varDir = "${ftpRoot}/var"; | |
2ff9258e IB |
10 | packagePath = "/var/lib/ftp/release.immae.eu/buildbot/Piedsjaloux"; |
11 | branch = "master"; | |
f8026b6e IB |
12 | in { |
13 | options.myServices.websites.piedsjaloux.production.enable = lib.mkEnableOption "enable PiedsJaloux's website in production"; | |
14 | ||
15 | config = lib.mkIf cfg.enable { | |
f8026b6e | 16 | services.webstats.sites = [ { name = "piedsjaloux.fr"; } ]; |
2ff9258e IB |
17 | services.phpfpm.pools.piedsjaloux_production = { |
18 | user = config.services.httpd.Prod.user; | |
19 | group = config.services.httpd.Prod.group; | |
20 | settings = { | |
21 | "listen.owner" = config.services.httpd.Prod.user; | |
22 | "listen.group" = config.services.httpd.Prod.group; | |
23 | "php_admin_value[open_basedir]" = builtins.concatStringsSep ":" [ | |
24 | ftpRoot | |
25 | config.secrets.fullPaths."websites/piedsjaloux/production" | |
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=PiedsJaloux: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.php74.withExtensions({ enabled, all }: enabled ++ [all.redis]); |
2ff9258e IB |
40 | }; |
41 | systemd.services."phpfpm-piedsjaloux_production" = { | |
42 | after = lib.mkAfter ["mysql.service"]; | |
43 | wants = ["mysql.service"]; | |
44 | path = lib.mkAfter [ pkgs.gnutar pkgs.gzip pkgs.php74 ]; | |
45 | preStart = let | |
46 | script = pkgs.writeScriptBin "piedsjaloux-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,data,miniatures,tmp} | |
61 | ln -sf ${varDir}/{logs,cache,data,miniatures,tmp} var/ | |
62 | ln -sf ${config.secrets.fullPaths."websites/piedsjaloux/production"} app/config/parameters.yml | |
63 | ./bin/console --env=${secrets.environment} cache:clear --no-warmup | |
64 | sha256sum ${packagePath}/${branch}.tar.gz > ${ftpRoot}/.tarball_sum | |
65 | ''; | |
66 | in | |
67 | "/run/wrappers/bin/sudo -u ${config.services.httpd.Prod.user} ${script}/bin/piedsjaloux-production-pre"; | |
68 | postStart = let | |
69 | script = pkgs.writeScriptBin "piedsjaloux-production-post" '' | |
70 | #! ${pkgs.stdenv.shell} | |
71 | ||
72 | cd ${ftpRoot} | |
73 | if [ -d php_old ]; then | |
74 | rm -rf php_old | |
75 | fi | |
76 | ''; | |
77 | in | |
78 | "/run/wrappers/bin/sudo -u ${config.services.httpd.Prod.user} ${script}/bin/piedsjaloux-production-post"; | |
79 | serviceConfig.TimeoutStartSec="infinity"; | |
80 | }; | |
81 | services.filesWatcher.phpfpm-piedsjaloux_production = { | |
82 | restart = true; | |
83 | paths = [ "${packagePath}/${branch}.tar.gz" ]; | |
84 | }; | |
85 | ||
86 | system.activationScripts.piedsjaloux_production = { | |
87 | deps = ["users"]; | |
88 | text = '' | |
bbea22c0 | 89 | install -m 0700 -o ${config.services.httpd.Prod.user} -g ${config.services.httpd.Prod.group} -d ${ftpRoot} |
2ff9258e | 90 | ''; |
8164ed90 IB |
91 | }; |
92 | ||
4c4652aa IB |
93 | secrets.keys."websites/piedsjaloux/production" = { |
94 | user = config.services.httpd.Prod.user; | |
95 | group = config.services.httpd.Prod.group; | |
96 | permissions = "0400"; | |
97 | text = '' | |
98 | # This file is auto-generated during the composer install | |
99 | parameters: | |
100 | database_host: ${secrets.mysql.host} | |
101 | database_port: ${secrets.mysql.port} | |
102 | database_name: ${secrets.mysql.database} | |
103 | database_user: ${secrets.mysql.user} | |
104 | database_password: ${secrets.mysql.password} | |
e34b3079 | 105 | database_server_version: ${config.myServices.databases.mariadb.package.mysqlVersion} |
4c4652aa IB |
106 | mailer_transport: smtp |
107 | mailer_host: 127.0.0.1 | |
108 | mailer_user: null | |
109 | mailer_password: null | |
110 | secret: ${secrets.secret} | |
111 | pdflatex: "${texlive}/bin/pdflatex" | |
112 | leapt_im: | |
113 | binary_path: ${pkgs.imagemagick}/bin | |
114 | ''; | |
115 | }; | |
f8026b6e | 116 | |
d3452fc5 | 117 | services.websites.env.production.vhostConfs.piedsjaloux_production = { |
f8026b6e IB |
118 | certName = "piedsjaloux"; |
119 | certMainHost = "piedsjaloux.fr"; | |
120 | hosts = [ "piedsjaloux.fr" "www.piedsjaloux.fr" ]; | |
2ff9258e | 121 | root = webRoot; |
8164ed90 IB |
122 | extraConfig = [ |
123 | '' | |
33b5010f IB |
124 | RewriteEngine on |
125 | RewriteCond "%{HTTP_HOST}" "!^www.piedsjaloux\.fr$" [NC] | |
126 | RewriteRule ^(.+)$ https://www.piedsjaloux.fr$1 [R=302,L] | |
127 | ||
8164ed90 | 128 | <FilesMatch "\.php$"> |
2ff9258e | 129 | SetHandler "proxy:unix:${config.services.phpfpm.pools.piedsjaloux_production.socket}|fcgi://localhost" |
8164ed90 IB |
130 | </FilesMatch> |
131 | ||
132 | Use Stats piedsjaloux.fr | |
133 | ||
2ff9258e | 134 | <Directory ${webRoot}> |
8164ed90 IB |
135 | Options Indexes FollowSymLinks MultiViews Includes |
136 | AllowOverride All | |
137 | Require all granted | |
138 | </Directory> | |
139 | '' | |
140 | ]; | |
f8026b6e IB |
141 | }; |
142 | }; | |
143 | } |