5454# Remove errornous history.log file created by certain builds due to bug in v-restart-system
5555if [ -e $HESTIA /data/users/history.log ]; then
5656 rm -f $HESTIA /data/users/history.log
57- fi
57+ fi
58+
59+ #
60+ # Migrate legacy multiphp to full php-fpm backend
61+ #
62+ # nginx+fpm (default)
63+ # nothing to be done here,
64+ # (Adding new php backends will make them available on edit/web)
65+ #
66+ # nginx+multiphp,
67+ # nginx+apache+multiphp,
68+ # apache+multiphp:
69+ # Change Hestia WEB_BACKEND from null to php-fpm
70+ # Create backend templates ex: PHP-7_3, PHP-5_6 (in $HESTIA/data/templates/web/php-fpm/)
71+ # v-update-web-templates
72+ # Loop trough all web domains
73+ # If official multiphp tpl is used ex: PHP-72, then change backend tpl and set app web template to default
74+ # ( old default.tpl backend maps to PHP-7_3 )
75+ # If not, parse php version from tpl file , fallback to latest version,
76+ # Copy all non-official tpls to php-fpm folder (as app web template includin bash script if present)
77+ #
78+ # a2 (non-fpm) or nginx+a2(non-fpm)
79+ # - Skipped
80+ #
81+
82+ DEFAULT_BTPL=" PHP-7_3"
83+ num_php_versions=$( ls -d /etc/php/* /fpm/pool.d 2> /dev/null | wc -l)
84+ echo $num_php_versions
85+
86+ if [ " $num_php_versions " -gt 1 ] && [ -z " $WEB_BACKEND " ]; then
87+ # Legacy multiphp
88+
89+ echo $num_php_versions
90+ sed -i " /^WEB_BACKEND=/d" $HESTIA /conf/hestia.conf
91+ echo " WEB_BACKEND='php-fpm'" >> $HESTIA /conf/hestia.conf
92+
93+ for php_ver in $( ls /etc/php/) ; do
94+ [ ! -d " /etc/php/$php_ver /fpm/pool.d/" ] && continue
95+ cp -f " $HESTIA_INSTALL_DIR /php-fpm/multiphp.tpl" ${WEBTPL} /php-fpm/PHP-${php_ver/ \. / _} .tpl
96+ done
97+
98+ if [ " $WEB_SYSTEM " = ' nginx' ] ]; then
99+ cp -rf " ${HESTIA_INSTALL_DIR} /templates/web/nginx" " ${WEBTPL} /"
100+ fi
101+
102+ # Migrate domains
103+ for user in $( $BIN /v-list-sys-users plain) ; do
104+ echo " Migrating legacy multiphp domains for user: $user "
105+ for domain in $( $BIN /v-list-web-domains $user plain | cut -f1) ; do
106+ echo " Processing domain: $domain "
107+ web_tpl=" default"
108+ backend_tpl=" $DEFAULT_BTPL "
109+ domain_tpl=$( $BIN /v-list-web-domain $user $domain | grep " ^TEMPLATE:" | awk ' {print $2;}' ) ;
110+
111+ if [ " $domain_tpl " = " PHP-56" ]; then
112+ backend_tpl=" PHP-5_6"
113+ elif [ " $domain_tpl " = " PHP-70" ]; then
114+ backend_tpl=" PHP-7_0"
115+ elif [ " $domain_tpl " = " PHP-71" ]; then
116+ backend_tpl=" PHP-7_1"
117+ elif [ " $domain_tpl " = " PHP-72" ]; then
118+ backend_tpl=" PHP-7_2"
119+ elif [ " $domain_tpl " = " PHP-73" ] || [ " $domain_tpl " = " default" ] || [ -z " $domain_tpl " ]; then
120+ backend_tpl=" PHP-7_3"
121+ else
122+ # Custom domain template used
123+ echo " Domain is using a custom multiphp template (or non-multiphp one)"
124+
125+ web_tpl=" $domain_tpl "
126+ if [ -f " ${WEBTPL} /$WEB_SYSTEM /php-fpm/$web_tpl .tpl" ]; then
127+ # php-fpm backend folder allready has a template with the same name
128+ web_tpl=" custom-$domain_tpl "
129+ fi
130+
131+ # Copy custom template to php-fpm backend folder
132+ mkdir -p " $WEBTPL /$WEB_SYSTEM /php-fpm"
133+ if [ -f " $WEBTPL /$WEB_SYSTEM /$domain_tpl .sh" ]; then
134+ cp " $WEBTPL /$WEB_SYSTEM /$domain_tpl .sh" " $WEBTPL /$WEB_SYSTEM /php-fpm/$web_tpl .sh"
135+ fi
136+ cp " $WEBTPL /$WEB_SYSTEM /$domain_tpl .tpl" " $WEBTPL /$WEB_SYSTEM /php-fpm/$web_tpl .tpl"
137+ cp " $WEBTPL /$WEB_SYSTEM /$domain_tpl .stpl" " $WEBTPL /$WEB_SYSTEM /php-fpm/$web_tpl .stpl"
138+
139+
140+ if [[ $( grep " unix:/" $WEBTPL /$WEB_SYSTEM /$domain_tpl .tpl | egrep -v " ^\s*#" | tail -n1) \
141+ =~ unix:\/ run\/ php\/ php([0-9]+\. [0-9]+)-fpm.+\. sock ]]; then
142+
143+ # Found a custom template that is based on official multiphp one
144+ backend_tpl=" PHP-${BASH_REMATCH[1]/ \. / _} "
145+ echo " Custom multiphp template ($domain_tpl ) compatible with backend: $backend_tpl "
146+
147+ # Remove multiphp switching script
148+ rm -f " $WEBTPL /$WEB_SYSTEM /php-fpm/$web_tpl .sh"
149+
150+ # Replace hardcoded php-fpm socket path with tpl variable, ignoring commented lines
151+ sed ' /^[[:space:]]*#/!s/unix:.*;/%backend_lsnr%;/g' " $WEBTPL /$WEB_SYSTEM /php-fpm/$web_tpl .tpl"
152+ sed ' /^[[:space:]]*#/!s/unix:.*;/%backend_lsnr%;/g' " $WEBTPL /$WEB_SYSTEM /php-fpm/$web_tpl .stpl"
153+ fi
154+ fi
155+
156+ echo " Parsed config: oldTPL=$domain_tpl newTPL:$web_tpl newBackTPL:$backend_tpl "
157+ $BIN /v-change-web-domain-tpl " $user " " $domain " " $web_tpl " " no"
158+ $BIN /v-change-web-domain-backend-tpl " $user " " $domain " " $backend_tpl " " no"
159+ echo -e " --done--\n"
160+ done
161+ done
162+
163+ # cleanup legacy multiphp templates
164+ for php_ver in $( ls /etc/php/) ; do
165+ [ ! -d " /etc/php/$php_ver /fpm/pool.d/" ] && continue
166+ echo " Remove legacy multiphp templates for: $php_ver "
167+ [ -f " $WEBTPL /$WEB_SYSTEM /PHP-${php_ver// .} .sh" ] && rm " $WEBTPL /$WEB_SYSTEM /PHP-${php_ver// .} .sh"
168+ [ -f " $WEBTPL /$WEB_SYSTEM /PHP-${php_ver// .} .tpl" ] && rm " $WEBTPL /$WEB_SYSTEM /PHP-${php_ver// .} .tpl"
169+ [ -f " $WEBTPL /$WEB_SYSTEM /PHP-${php_ver// .} .stpl" ] && rm " $WEBTPL /$WEB_SYSTEM /PHP-${php_ver// .} .stpl"
170+ done
171+
172+ # Remove default symlinks
173+ [ -f " $WEBTPL /$WEB_SYSTEM /default.sh" ] && rm " $WEBTPL /$WEB_SYSTEM /default.sh"
174+ [ -f " $WEBTPL /$WEB_SYSTEM /default.tpl" ] && rm " $WEBTPL /$WEB_SYSTEM /default.tpl"
175+ [ -f " $WEBTPL /$WEB_SYSTEM /default.stpl" ] && rm " $WEBTPL /$WEB_SYSTEM /default.stpl"
176+
177+
178+ $BIN /v-update-web-templates ' no'
179+ fi
180+
0 commit comments