]>
Commit | Line | Data |
---|---|---|
ab8f306d | 1 | { lib, pkgs, config, ... }: |
f8026b6e | 2 | let |
d3452fc5 | 3 | secrets = config.myEnv.websites.ludivine.production; |
d3452fc5 | 4 | cfg = config.myServices.websites.ludivine.production; |
2ff9258e IB |
5 | ftpRoot = "/var/lib/ludivine_production"; |
6 | phpRoot = "${ftpRoot}/php"; | |
7 | webRoot = "${phpRoot}/web"; | |
8 | varDir = "${ftpRoot}/var"; | |
9 | sessionDir = "${ftpRoot}/sessions"; | |
10 | packagePath = "/var/lib/ftp/release.immae.eu/buildbot/Ludivine"; | |
11 | branch = "master"; | |
f8026b6e | 12 | in { |
d3452fc5 | 13 | options.myServices.websites.ludivine.production.enable = lib.mkEnableOption "enable Ludivine's website in production"; |
f8026b6e IB |
14 | |
15 | config = lib.mkIf cfg.enable { | |
f8026b6e | 16 | services.webstats.sites = [ { name = "ludivinecassal.com"; } ]; |
2ff9258e IB |
17 | services.phpfpm.pools.ludivine_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/ludivine/production" | |
26 | "/tmp" | |
27 | ]; | |
28 | "php_admin_value[session.save_path]" = sessionDir; | |
5400b9b6 IB |
29 | "php_admin_value[upload_max_filesize]" = "20M"; |
30 | "php_admin_value[post_max_size]" = "20M"; | |
31 | #"php_admin_flag[log_errors]" = "on"; | |
32 | "pm" = "dynamic"; | |
33 | "pm.max_children" = "20"; | |
34 | "pm.start_servers" = "2"; | |
35 | "pm.min_spare_servers" = "1"; | |
36 | "pm.max_spare_servers" = "3"; | |
37 | }; | |
dcac3ec7 | 38 | phpPackage = pkgs.php72; |
8164ed90 | 39 | }; |
2ff9258e IB |
40 | systemd.services."phpfpm-ludivine_production" = { |
41 | after = lib.mkAfter ["mysql.service"]; | |
42 | wants = ["mysql.service"]; | |
43 | path = lib.mkAfter [ pkgs.gnutar pkgs.gzip pkgs.php72 ]; | |
44 | preStart = let | |
45 | script = pkgs.writeScriptBin "ludivine-production-pre" '' | |
46 | #! ${pkgs.stdenv.shell} | |
47 | ||
48 | [ -f ${packagePath}/${branch}.tar.gz ] || exit 1 | |
49 | ||
50 | cd ${ftpRoot} | |
51 | if ! [ -f .tarball_sum ] || ! sha256sum -c .tarball_sum; then | |
52 | tar -xf ${packagePath}/${branch}.tar.gz --one-top-level=php_new | |
53 | if [ -d php ]; then | |
54 | mv php php_old | |
55 | fi | |
56 | mv php_new php | |
57 | fi | |
58 | cd php | |
59 | rm -rf var/{logs,cache,data,miniatures,tmp} | |
60 | ln -sf ${varDir}/{logs,cache,data,miniatures,tmp} var/ | |
61 | ln -sf ${config.secrets.fullPaths."websites/ludivine/production"} app/config/parameters.yml | |
62 | ./bin/console --env=${secrets.environment} cache:clear --no-warmup | |
63 | sha256sum ${packagePath}/${branch}.tar.gz > ${ftpRoot}/.tarball_sum | |
64 | ''; | |
65 | in | |
66 | "/run/wrappers/bin/sudo -u ${config.services.httpd.Prod.user} ${script}/bin/ludivine-production-pre"; | |
67 | postStart = let | |
68 | script = pkgs.writeScriptBin "ludivine-production-post" '' | |
69 | #! ${pkgs.stdenv.shell} | |
70 | ||
71 | cd ${ftpRoot} | |
72 | if [ -d php_old ]; then | |
73 | rm -rf php_old | |
74 | fi | |
75 | ''; | |
76 | in | |
77 | "/run/wrappers/bin/sudo -u ${config.services.httpd.Prod.user} ${script}/bin/ludivine-production-post"; | |
78 | serviceConfig.TimeoutStartSec="infinity"; | |
79 | }; | |
80 | services.filesWatcher.phpfpm-ludivine_production = { | |
81 | restart = true; | |
82 | paths = [ "${packagePath}/${branch}.tar.gz" ]; | |
83 | }; | |
84 | ||
85 | system.activationScripts.ludivine_production = { | |
86 | deps = []; | |
87 | text = '' | |
88 | install -m 0700 -o ${config.services.httpd.Prod.user} -g ${config.services.httpd.Prod.group} -d ${ftpRoot} ${sessionDir} | |
89 | ''; | |
90 | }; | |
8164ed90 | 91 | |
4c4652aa IB |
92 | secrets.keys."websites/ludivine/production" = { |
93 | user = config.services.httpd.Prod.user; | |
94 | group = config.services.httpd.Prod.group; | |
95 | permissions = "0400"; | |
96 | text = '' | |
97 | # This file is auto-generated during the composer install | |
98 | parameters: | |
99 | database_host: ${secrets.mysql.host} | |
100 | database_port: ${secrets.mysql.port} | |
101 | database_name: ${secrets.mysql.database} | |
102 | database_user: ${secrets.mysql.user} | |
103 | database_password: ${secrets.mysql.password} | |
e34b3079 | 104 | database_server_version: ${config.myServices.databases.mariadb.package.mysqlVersion} |
4c4652aa IB |
105 | mailer_transport: smtp |
106 | mailer_host: 127.0.0.1 | |
107 | mailer_user: null | |
108 | mailer_password: null | |
109 | secret: ${secrets.secret} | |
110 | ldap_host: ldap.immae.eu | |
111 | ldap_port: 636 | |
112 | ldap_version: 3 | |
113 | ldap_ssl: true | |
114 | ldap_tls: false | |
115 | ldap_user_bind: 'uid={username},ou=users,dc=immae,dc=eu' | |
116 | ldap_base_dn: 'dc=immae,dc=eu' | |
117 | ldap_search_dn: '${secrets.ldap.dn}' | |
118 | ldap_search_password: '${secrets.ldap.password}' | |
119 | ldap_search_filter: '${secrets.ldap.filter}' | |
120 | leapt_im: | |
121 | binary_path: ${pkgs.imagemagick}/bin | |
122 | assetic: | |
123 | sass: ${pkgs.sass}/bin/sass | |
124 | ruby: ${pkgs.ruby}/bin/ruby | |
125 | ''; | |
126 | }; | |
f8026b6e | 127 | |
d3452fc5 IB |
128 | services.websites.env.production.vhostConfs.ludivine_production = { |
129 | certName = "ludivine"; | |
f8026b6e IB |
130 | certMainHost = "ludivinecassal.com"; |
131 | hosts = ["ludivinecassal.com" "www.ludivinecassal.com" ]; | |
2ff9258e | 132 | root = webRoot; |
8164ed90 IB |
133 | extraConfig = [ |
134 | '' | |
33b5010f IB |
135 | RewriteEngine on |
136 | RewriteCond "%{HTTP_HOST}" "!^ludivinecassal\.com$" [NC] | |
137 | RewriteRule ^(.+)$ https://ludivinecassal.com$1 [R=302,L] | |
138 | ||
8164ed90 | 139 | <FilesMatch "\.php$"> |
2ff9258e | 140 | SetHandler "proxy:unix:${config.services.phpfpm.pools.ludivine_production.socket}|fcgi://localhost" |
8164ed90 IB |
141 | </FilesMatch> |
142 | ||
143 | Use Stats ludivinecassal.com | |
144 | ||
2ff9258e | 145 | <Directory ${webRoot}> |
8164ed90 IB |
146 | Options Indexes FollowSymLinks MultiViews Includes |
147 | AllowOverride All | |
148 | Require all granted | |
149 | </Directory> | |
150 | '' | |
151 | ]; | |
17f6eae9 | 152 | }; |
f8026b6e IB |
153 | }; |
154 | } |