From ba769be23a526eeec4e08122c20383d663bdfbbf Mon Sep 17 00:00:00 2001 From: ewilly Date: Sat, 26 May 2018 13:17:41 +0200 Subject: [PATCH] Refractoring & stretch update --- conf/nginx.conf | 2 +- conf/php-fpm.conf | 12 ++++++------ manifest.json | 17 ----------------- scripts/_common.sh | 34 ---------------------------------- scripts/install | 37 ++++++++++--------------------------- scripts/remove | 2 -- scripts/restore | 6 ++---- scripts/upgrade | 31 ++++++++----------------------- 8 files changed, 27 insertions(+), 114 deletions(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index 8c3abac..9e68c3e 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -16,7 +16,7 @@ location __PATH__/ { add_header X-Permitted-Cross-Domain-Policies none; # Set max upload size - client_max_body_size __FILESIZE__; + client_max_body_size 10G; client_body_timeout 30m; proxy_read_timeout 30m; fastcgi_buffers 64 4K; diff --git a/conf/php-fpm.conf b/conf/php-fpm.conf index d47a9f3..b04f62d 100644 --- a/conf/php-fpm.conf +++ b/conf/php-fpm.conf @@ -1,6 +1,6 @@ -[__NAME__] +[__NAMETOCHANGE__] ; The address on which to accept FastCGI requests. -listen = /var/run/php5-fpm-__NAME__.sock +listen = /var/run/php5-fpm-__NAMETOCHANGE__.sock ; Set permissions for unix socket, if one is used. listen.owner = www-data @@ -8,8 +8,8 @@ listen.group = www-data listen.mode = 0600 ; Unix user/group of processes. -user = __NAME__ -group = __NAME__ +user = __USER__ +group = __USER__ ; Choose how the process manager will control the number of child processes. pm = dynamic @@ -65,7 +65,7 @@ catch_workers_output = yes clear_env = no ; Additional php.ini defines, specific to this pool of workers. -php_value[upload_max_filesize] = __FILESIZE__ -php_value[post_max_size] = __POSTSIZE__ +php_value[upload_max_filesize] = 10G +php_value[post_max_size] = 10G php_value[default_charset] = UTF-8 php_value[always_populate_raw_post_data] = -1 diff --git a/manifest.json b/manifest.json index 7884530..df43af1 100644 --- a/manifest.json +++ b/manifest.json @@ -51,23 +51,6 @@ }, "default": false }, - { - "name": "language", - "ask": { - "en": "Language (if the browser language is not detected)", - "fr": "Langue (si la langue du navigateur n'est pas détectée)" - }, - "choices": ["de","en","es","fr"], - "default": "en" - }, - { - "name": "filesize", - "ask": { - "en": "Define the file upload size limit", - "fr": "Définissez la taille limite de téléchargement" - }, - "default": "2G" - }, { "name": "admin", "type": "user", diff --git a/scripts/_common.sh b/scripts/_common.sh index 502ecc8..8d5af50 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -38,40 +38,6 @@ myynh_clean_source () { [ -e "$TMPDIR/.gitignore" ] && rm -r "$TMPDIR/.gitignore" } -# Create a dedicated nginx config -myynh_add_nginx_config () { - ynh_backup_if_checksum_is_different "$nginx_conf" 1 - cp ../conf/nginx.conf "$nginx_conf" - # To avoid a break by set -u, use a void substitution ${var:-}. If the variable is not set, it's simply set with an empty variable. - # Substitute in a nginx config file only if the variable is not empty - if test -n "${path_url:-}"; then - if [ "${path_url:-}" != "/" ]; then - ynh_replace_string "^#sub_path_only " "" "$nginx_conf" - ynh_replace_string "__PATH__" "$path_url" "$nginx_conf" - else - ynh_replace_string "location\( \(=\|~\|~\*\|\^~\)\)\? __PATH__/" "location\1 $path_url" "$nginx_conf" - fi - fi - [ -n "${final_path:-}" ] && ynh_replace_string "__FINALPATH__" "$final_path" "$nginx_conf" - [ -n "${app:-}" ] && ynh_replace_string "__NAME__" "$app" "$nginx_conf" - [ -n "${filesize:-}" ] && ynh_replace_string "__FILESIZE__" "$filesize" "$nginx_conf" - ynh_store_file_checksum "$nginx_conf" - systemctl reload nginx -} -# Create a dedicated php-fpm config -myynh_add_fpm_config () { - ynh_backup_if_checksum_is_different "$phpfpm_conf" 1 - cp ../conf/php-fpm.conf "$phpfpm_conf" - postsize=${filesize%?}.1${filesize: -1} - ynh_replace_string "__FINALPATH__" "$final_path" "$phpfpm_conf" - ynh_replace_string "__NAME__" "$app" "$phpfpm_conf" - ynh_replace_string "__FILESIZE__" "$filesize" "$phpfpm_conf" - ynh_replace_string "__POSTSIZE__" "$postsize" "$phpfpm_conf" - chown root: "$phpfpm_conf" - ynh_store_file_checksum "$phpfpm_conf" - systemctl reload php5-fpm -} - myynh_set_permissions () { [ $(find "$final_path" -type f | wc -l) -gt 0 ] && find "$final_path" -type f | xargs chmod 0644 [ $(find "$final_path" -type d | wc -l) -gt 0 ] && find "$final_path" -type d | xargs chmod 0755 diff --git a/scripts/install b/scripts/install index f014c52..4fc7964 100644 --- a/scripts/install +++ b/scripts/install @@ -12,8 +12,6 @@ app=$YNH_APP_INSTANCE_NAME domain=$YNH_APP_ARG_DOMAIN path_url=$YNH_APP_ARG_PATH is_public=$YNH_APP_ARG_IS_PUBLIC -language=$YNH_APP_ARG_LANGUAGE -filesize=$YNH_APP_ARG_FILESIZE admin=$YNH_APP_ARG_ADMIN password=$YNH_APP_ARG_PASSWORD backup_core_only=$YNH_APP_ARG_BACKUP_CORE_ONLY @@ -21,10 +19,6 @@ backup_core_only=$YNH_APP_ARG_BACKUP_CORE_ONLY # definie useful vars final_path="/var/www/$app" data_path="/home/yunohost.app/$app" -bozon_conf="$final_path/config.php" -bozon_auto_dropzone_php="$final_path/core/auto_dropzone.php" -nginx_conf="/etc/nginx/conf.d/$domain.d/$app.conf" -phpfpm_conf="/etc/php5/fpm/pool.d/$app.conf" # check domain/path availability path_url=$(ynh_normalize_url_path "$path_url") @@ -42,8 +36,6 @@ ynh_install_app_dependencies "$PKG_DEPENDENCIES" ynh_app_setting_set "$app" domain "$domain" ynh_app_setting_set "$app" path "$path_url" ynh_app_setting_set "$app" is_public $is_public -ynh_app_setting_set "$app" filesize "$filesize" -ynh_app_setting_set "$app" language "$language" ynh_app_setting_set "$app" admin_user "$admin" ynh_app_setting_set "$app" backup_core_only $backup_core_only @@ -58,23 +50,6 @@ ynh_setup_source "$TMPDIR" myynh_clean_source mv "$TMPDIR" "$final_path" -# configure config file - # language -ynh_replace_string "default_language='en'" "default_language='$language'" "$bozon_conf" - - # max upload file size -case ${filesize: -1} in - g|G) - max_length=$((${filesize%?}*1024)) - ;; - *) - max_length=${filesize%?} - ;; - esac -ynh_replace_string "max_length=2048" "max_length=$max_length" "$bozon_conf" - -ynh_store_file_checksum "$bozon_conf" - # create private & data folders myynh_create_dir "$final_path/private" myynh_create_dir "$data_path/uploads" @@ -86,10 +61,18 @@ ln -s "$data_path/thumbs" "$final_path/thumbs" myynh_set_permissions # configure nginx settings -myynh_add_nginx_config +if test -n "${path_url:-}"; then + if [ "${path_url:-}" != "/" ]; then + ynh_replace_string "^#sub_path_only " "" "../conf/nginx.conf" + ynh_replace_string "__PATH__" "$path_url" "../conf/nginx.conf" + else + ynh_replace_string "location\( \(=\|~\|~\*\|\^~\)\)\? __PATH__/" "location\1 $path_url" "../conf/nginx.conf" + fi +fi +ynh_add_nginx_config # copy and set php-fpm configuration -myynh_add_fpm_config +ynh_add_fpm_config # set temporary public access for curl call ynh_app_setting_set "$app" unprotected_uris "/" diff --git a/scripts/remove b/scripts/remove index db99523..31cc4a3 100644 --- a/scripts/remove +++ b/scripts/remove @@ -21,8 +21,6 @@ domain=$(ynh_app_setting_get "$app" domain) # definie useful vars final_path="/var/www/$app" data_path="/home/yunohost.app/$app" -nginx_conf="/etc/nginx/conf.d/$domain.d/$app.conf" -phpfpm_conf="/etc/php5/fpm/pool.d/$app.conf" # create a full backup (core+datas) if app installed if [ $(yunohost app list -i -f "$app" | wc -l) -gt 1 ]; then diff --git a/scripts/restore b/scripts/restore index fd155eb..2ea3dec 100644 --- a/scripts/restore +++ b/scripts/restore @@ -25,8 +25,6 @@ backup_core_only=$(ynh_app_setting_get "$app" backup_core_only) # definie useful vars final_path="/var/www/$app" data_path="/home/yunohost.app/$app" -nginx_conf="/etc/nginx/conf.d/$domain.d/$app.conf" -phpfpm_conf="/etc/php5/fpm/pool.d/$app.conf" # check domain/path availability ynh_webpath_available "$domain" "$path_url" @@ -39,8 +37,8 @@ ynh_install_app_dependencies "$PKG_DEPENDENCIES" ynh_system_user_create "$app" # restore sconf files -ynh_restore_file "$nginx_conf" -ynh_restore_file "$phpfpm_conf" +ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_restore_file "/etc/php5/fpm/pool.d/$app.conf" # restore source ynh_restore_file "$final_path" diff --git a/scripts/upgrade b/scripts/upgrade index da0488a..0108162 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -12,18 +12,12 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get "$app" domain) path_url=$(ynh_app_setting_get "$app" path) is_public=$(ynh_app_setting_get "$app" is_public) -filesize=$(ynh_app_setting_get "$app" filesize) -language=$(ynh_app_setting_get "$app" language) admin_user=$(ynh_app_setting_get "$app" admin_user) backup_core_only=$(ynh_app_setting_get "$app" backup_core_only) # definie useful vars final_path="/var/www/$app" data_path="/home/yunohost.app/$app" -bozon_conf="$final_path/config.php" -bozon_auto_dropzone_php="$final_path/core/auto_dropzone.php" -nginx_conf="/etc/nginx/conf.d/$domain.d/$app.conf" -phpfpm_conf="/etc/php5/fpm/pool.d/$app.conf" # use prior backup and restore on error only if backup feature exists on installed instance if [ -f "/etc/yunohost/apps/$app/scripts/backup" ] ; then @@ -49,27 +43,14 @@ myynh_clean_source cp -a "$TMPDIR/." "$final_path" rm -R "$TMPDIR" -# Only add 'max_length' line in config.php if does not exist yet -if [ $(grep "max_length=" "$bozon_conf" | wc -l) -eq 0 ]; then - case ${filesize: -1} in - g|G) - max_length=$((${filesize%?}*1024)) - ;; - *) - max_length=${filesize%?} - ;; - esac - sed -i "54i\$max_length=$max_length;" "$bozon_conf" -fi - # set permissions myynh_set_permissions # configure nginx settings -myynh_add_nginx_config +ynh_add_nginx_config # copy and set php-fpm configuration -myynh_add_fpm_config +ynh_add_fpm_config # if app is private, remove url to SSOWat conf from skipped_uris if [ $is_public -eq 0 ] @@ -84,5 +65,9 @@ else ynh_app_setting_set "$app" unprotected_uris "/" fi -# Purge php sessions stored in /var/lib/php5/sessions -[ -x /usr/lib/php5/sessionclean ] && /usr/lib/php5/sessionclean +# Purge php sessions stored in /var/lib/phpx/sessions +if [ -d "/usr/lib/php5" ]; then + [ -x /usr/lib/php5/sessionclean ] && /usr/lib/php5/sessionclean +elif [ -d "/usr/lib/php" ]; then + [ -x /usr/lib/php/sessionclean ] && /usr/lib/php/sessionclean +fi