]>
Commit | Line | Data |
---|---|---|
1 | { lib, pkgs, config, ... }: | |
2 | let | |
3 | secrets = config.myEnv.websites.connexionswing.production; | |
4 | cfg = config.myServices.websites.connexionswing.production; | |
5 | ftpRoot = "/var/lib/connexionswing_production"; | |
6 | phpRoot = "${ftpRoot}/php"; | |
7 | webRoot = "${phpRoot}/web"; | |
8 | varDir = "${ftpRoot}/var"; | |
9 | packagePath = "/var/lib/ftp/release.immae.eu/buildbot/Connexionswing"; | |
10 | branch = "master"; | |
11 | in { | |
12 | options.myServices.websites.connexionswing.production.enable = lib.mkEnableOption "enable Connexionswing's website in production"; | |
13 | ||
14 | config = lib.mkIf cfg.enable { | |
15 | services.webstats.sites = [ { name = "connexionswing.com"; } ]; | |
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 | ]; | |
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:'"; | |
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 | }; | |
39 | phpPackage = pkgs.php72.withExtensions ({ enabled, all }: enabled ++ [all.redis]); | |
40 | }; | |
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 = '' | |
90 | install -m 0700 -o ${config.services.httpd.Prod.user} -g ${config.services.httpd.Prod.group} -d ${ftpRoot} | |
91 | ''; | |
92 | }; | |
93 | ||
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} | |
106 | database_server_version: ${config.myServices.databases.mariadb.package.mysqlVersion} | |
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 | }; | |
120 | ||
121 | services.websites.env.production.vhostConfs.connexionswing_production = { | |
122 | certName = "connexionswing"; | |
123 | certMainHost = "connexionswing.com"; | |
124 | hosts = ["connexionswing.com" "sandetludo.com" "www.connexionswing.com" "www.sandetludo.com" ]; | |
125 | root = webRoot; | |
126 | extraConfig = [ | |
127 | '' | |
128 | <FilesMatch "\.php$"> | |
129 | SetHandler "proxy:unix:${config.services.phpfpm.pools.connexionswing_production.socket}|fcgi://localhost" | |
130 | </FilesMatch> | |
131 | ||
132 | <Directory ${varDir}/medias> | |
133 | Options FollowSymLinks | |
134 | AllowOverride None | |
135 | Require all granted | |
136 | </Directory> | |
137 | ||
138 | <Directory ${varDir}/uploads> | |
139 | Options FollowSymLinks | |
140 | AllowOverride None | |
141 | Require all granted | |
142 | </Directory> | |
143 | ||
144 | Use Stats connexionswing.com | |
145 | ||
146 | <Directory ${webRoot}> | |
147 | Options Indexes FollowSymLinks MultiViews Includes | |
148 | AllowOverride All | |
149 | Require all granted | |
150 | </Directory> | |
151 | '' | |
152 | ]; | |
153 | }; | |
154 | }; | |
155 | } |