From b6d9f89e5c8231ced07f636f6fefc01d83ccbc41 Mon Sep 17 00:00:00 2001 From: ewilly Date: Mon, 23 May 2016 20:59:08 +0200 Subject: [PATCH] Fix timed out sur gros fichiers #15 --- conf/nginx.conf | 1 - conf/php-fpm.conf | 71 +++++++++++++++++++++++++++++++++++++++++++++++ scripts/backup | 3 +- scripts/install | 25 +++++++++++++---- scripts/remove | 8 ++++-- scripts/restore | 10 ++++++- scripts/upgrade | 31 +++++++++++++-------- 7 files changed, 127 insertions(+), 22 deletions(-) create mode 100644 conf/php-fpm.conf diff --git a/conf/nginx.conf b/conf/nginx.conf index 664a963..28645b9 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -13,7 +13,6 @@ location YNH_EXAMPLE_PATH { fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; include fastcgi_params; - fastcgi_param PHP_VALUE "upload_max_filesize = YNH_FILE_SIZE \n post_max_size=YNH_POST_SIZE"; fastcgi_param REMOTE_USER $remote_user; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $request_filename; diff --git a/conf/php-fpm.conf b/conf/php-fpm.conf new file mode 100644 index 0000000..c061f55 --- /dev/null +++ b/conf/php-fpm.conf @@ -0,0 +1,71 @@ +[YNH_EXAMPLE_APP] +; The address on which to accept FastCGI requests. +listen = /var/run/php5-fpm-YNH_EXAMPLE_APP.sock + +; Set permissions for unix socket, if one is used. +listen.owner = www-data +listen.group = www-data +listen.mode = 0600 + +; Unix user/group of processes. +user = www-data +group = www-data + +; Choose how the process manager will control the number of child processes. +pm = dynamic + +; The number of child processes to be created when pm is set to 'static' and the +; maximum number of child processes to be created when pm is set to 'dynamic'. +pm.max_children = 6 + +; The number of child processes created on startup. +pm.start_servers = 3 + +; The desired minimum number of idle server processes. +pm.min_spare_servers = 3 + +; The desired maximum number of idle server processes. +pm.max_spare_servers = 5 + +; The number of requests each child process should execute before respawning. +pm.max_requests = 500 + +; The URI to view the FPM status page. If this value is not set, no URI will be +; recognized as a status page. +pm.status_path = /fpm-status + +; The ping URI to call the monitoring page of FPM. If this value is not set, no +; URI will be recognized as a ping page. +ping.path = /ping + +; The timeout for serving a single request after which the worker process will +; be killed. +request_terminate_timeout = 1d + +; The timeout for serving a single request after which a PHP backtrace will be +; dumped to the 'slowlog' file. A value of '0s' means 'off'. +request_slowlog_timeout = 5s + +; The log file for slow requests. +slowlog = /var/log/nginx/YNH_EXAMPLE_APP.slow.log + +; Set open file descriptor rlimit. +rlimit_files = 4096 + +; Set max core size rlimit. +rlimit_core = 0 + +; Chdir to this directory at the start. +chdir = YNH_EXAMPLE_ALIAS + +; Redirect worker stdout and stderr into main error log. +catch_workers_output = yes + +; Do not clear environment in FPM workers. +clear_env = no + +; Additional php.ini defines, specific to this pool of workers. +php_value[upload_max_filesize] = YNH_FILE_SIZE +php_value[post_max_size] = YNH_POST_SIZE +php_value[default_charset] = UTF-8 +php_value[always_populate_raw_post_data] = -1 diff --git a/scripts/backup b/scripts/backup index a57693f..63b2665 100644 --- a/scripts/backup +++ b/scripts/backup @@ -17,6 +17,7 @@ domain=$(sudo yunohost app setting $app domain) sudo cp -R $final_path/. $save_path/www/ sudo cp -R $data_path/. $save_path/datas/ -# backup Nginx and YunoHost parameters +# backup php-fpm, Nginx and YunoHost parameters sudo cp -a /etc/yunohost/apps/$app/. $save_path/yunohost/ sudo cp -a /etc/nginx/conf.d/$domain.d/$app.conf $save_path/nginx.conf +sudo cp -a /etc/php5/fpm/pool.d/$app.conf $save_path/php-fpm.conf diff --git a/scripts/install b/scripts/install index 863c1e9..7bfe9de 100644 --- a/scripts/install +++ b/scripts/install @@ -76,16 +76,28 @@ sudo chown -R www-data: $data_path/uploads sudo chown -R www-data: $data_path/thumbs # configure nginx settings -## file upload size limit -postsize=${filesize%?}.1${filesize: -1} -sudo sed -i "s@YNH_FILE_SIZE@$filesize@g" ../conf/nginx.conf -sudo sed -i "s@YNH_POST_SIZE@$postsize@g" ../conf/nginx.conf ## path sudo sed -i "s@YNH_EXAMPLE_PATH@$path@g" ../conf/nginx.conf sudo sed -i "s@YNH_EXAMPLE_ALIAS@$final_path@g" ../conf/nginx.conf - +## file upload size limit +sudo sed -i "s@YNH_FILE_SIZE@${filesize}@g" ../conf/nginx.conf +## copy final sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf +# copy and set php-fpm configuration +## path +sed -i "s@YNH_EXAMPLE_APP@${app}@g" ../conf/php-fpm.conf +sed -i "s@YNH_EXAMPLE_ALIAS@${final_path}@g" ../conf/php-fpm.conf +## file upload size limit +sudo sed -i "s@YNH_FILE_SIZE@${filesize}@g" ../conf/php-fpm.conf +postsize=${filesize%?}.1${filesize: -1} +sudo sed -i "s@YNH_POST_SIZE@${postsize}@g" ../conf/php-fpm.conf +## copy final and set permissions +phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf" +sudo cp ../conf/php-fpm.conf "$phpfpm_conf" +sudo chown root: $phpfpm_conf +sudo chmod 644 $phpfpm_conf + # create the superadmin ## set temporary public access sudo yunohost app setting $app unprotected_uris -v "/" @@ -113,5 +125,6 @@ then fi # restart services -sudo service nginx reload +sudo service php5-fpm restart || true +sudo service nginx restart || true sudo yunohost app ssowatconf diff --git a/scripts/remove b/scripts/remove index e004755..24f0957 100644 --- a/scripts/remove +++ b/scripts/remove @@ -2,14 +2,18 @@ # causes the shell to exit if any subcommand or pipeline returns a non-zero status set -e +# causes the shell to exit if you try to use an uninitialised variable +set -u app=bozon domain=$(sudo yunohost app setting $app domain) sudo rm -rf /var/www/$app sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf +sudo rm -f /etc/php5/fpm/pool.d/$app.conf sudo rm -rf /home/yunohost.app/$app -# restart services -sudo service nginx reload +# Restart services +sudo service php5-fpm restart || true +sudo service nginx restart || true sudo yunohost app ssowatconf diff --git a/scripts/restore b/scripts/restore index 223eb76..5b62d98 100644 --- a/scripts/restore +++ b/scripts/restore @@ -2,6 +2,8 @@ # causes the shell to exit if any subcommand or pipeline returns a non-zero status set -e +# causes the shell to exit if you try to use an uninitialised variable +set -u # definie useful vars app=bozon @@ -25,6 +27,12 @@ sudo chown -R www-data: $final_path/private sudo chown -R www-data: $data_path/uploads sudo chown -R www-data: $data_path/thumbs -# restore Nginx and YunoHost parameters +# restore php-fpm, Nginx and YunoHost parameters sudo cp -a $save_path/yunohost/. /etc/yunohost/apps/$app/ sudo cp -a $save_path/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf +sudo cp -a $save_path/php-fpm.conf /etc/php5/fpm/pool.d/$app.conf + +# Restart services +sudo service php5-fpm restart || true +sudo service nginx restart || true +sudo yunohost app ssowatconf diff --git a/scripts/upgrade b/scripts/upgrade index ae2998a..a8751d3 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -38,21 +38,29 @@ sudo rsync -avz --exclude="config.php" --exclude=".htaccess" $parent_path/BoZoN- sudo rm -R $parent_path/BoZoN-$stable # configure nginx settings -## file upload size limit -postsize=${filesize%?}.1${filesize: -1} -sudo sed -i "s@YNH_FILE_SIZE@$filesize@g" ../conf/nginx.conf -sudo sed -i "s@YNH_POST_SIZE@$postsize@g" ../conf/nginx.conf ## path folder_path=${path%/} sudo sed -i "s@YNH_EXAMPLE_PATH@$path@g" ../conf/nginx.conf -# if path is only / (without subfolder), add trailing slash to alias -alias_path=$final_path -[ "$path" == '/' ] && alias_path=$alias_path'/' -sudo sed -i "s@YNH_EXAMPLE_ALIAS@$alias_path@g" ../conf/nginx.conf -sudo sed -i "s@YNH_EXAMPLE_FOLDER@$folder_path@g" ../conf/nginx.conf - +sudo sed -i "s@YNH_EXAMPLE_ALIAS@$final_path@g" ../conf/nginx.conf +## file upload size limit +sudo sed -i "s@YNH_FILE_SIZE@${filesize}@g" ../conf/nginx.conf +## copy final sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf +# copy and set php-fpm configuration +## path +sed -i "s@YNH_EXAMPLE_APP@${app}@g" ../conf/php-fpm.conf +sed -i "s@YNH_EXAMPLE_ALIAS@${final_path}@g" ../conf/php-fpm.conf +## file upload size limit +sudo sed -i "s@YNH_FILE_SIZE@${filesize}@g" ../conf/php-fpm.conf +postsize=${filesize%?}.1${filesize: -1} +sudo sed -i "s@YNH_POST_SIZE@${postsize}@g" ../conf/php-fpm.conf +## copy final and set permissions +phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf" +sudo cp ../conf/php-fpm.conf "$phpfpm_conf" +sudo chown root: $phpfpm_conf +sudo chmod 644 $phpfpm_conf + # if app is private, remove url to SSOWat conf from skipped_uris if [ "$is_public" = "No" ]; then @@ -65,5 +73,6 @@ then fi # Restart services -sudo service nginx reload +sudo service php5-fpm restart || true +sudo service nginx restart || true sudo yunohost app ssowatconf