Skip to content

Commit 41f915b

Browse files
committed
Move multiphp upgrade procedure to a independent migration script
1 parent 9ae4cc5 commit 41f915b

File tree

2 files changed

+127
-122
lines changed

2 files changed

+127
-122
lines changed
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
#!/bin/bash
2+
3+
# Includes
4+
source $HESTIA/func/main.sh
5+
source $HESTIA/conf/hestia.conf
6+
7+
#
8+
# Migrate legacy multiphp to full php-fpm backend
9+
#
10+
# nginx+fpm (default)
11+
# nothing to be done here,
12+
# (Adding new php backends will make them available on edit/web)
13+
#
14+
# nginx+multiphp,
15+
# nginx+apache+multiphp,
16+
# apache+multiphp:
17+
# Change Hestia WEB_BACKEND from null to php-fpm
18+
# Create backend templates ex: PHP-7_3, PHP-5_6 (in $HESTIA/data/templates/web/php-fpm/)
19+
# v-update-web-templates
20+
# Loop trough all web domains
21+
# If official multiphp tpl is used ex: PHP-72, then change backend tpl and set app web template to default
22+
# ( old default.tpl backend maps to PHP-7_3 )
23+
# If not, parse php version from tpl file , fallback to latest version,
24+
# Copy all non-official tpls to php-fpm folder (as app web template includin bash script if present)
25+
#
26+
# a2 (non-fpm) or nginx+a2(non-fpm)
27+
# - Skipped
28+
#
29+
30+
DEFAULT_BTPL="PHP-7_3"
31+
num_php_versions=$(ls -d /etc/php/*/fpm/pool.d 2>/dev/null |wc -l)
32+
echo $num_php_versions
33+
34+
if [ "$num_php_versions" -gt 1 ] && [ -z "$WEB_BACKEND" ]; then
35+
# Legacy multiphp
36+
37+
echo $num_php_versions
38+
sed -i "/^WEB_BACKEND=/d" $HESTIA/conf/hestia.conf
39+
echo "WEB_BACKEND='php-fpm'" >> $HESTIA/conf/hestia.conf
40+
41+
for php_ver in $(ls /etc/php/); do
42+
[ ! -d "/etc/php/$php_ver/fpm/pool.d/" ] && continue
43+
cp -f "$HESTIA_INSTALL_DIR/php-fpm/multiphp.tpl" ${WEBTPL}/php-fpm/PHP-${php_ver/\./_}.tpl
44+
done
45+
46+
if [ "$WEB_SYSTEM" = 'nginx' ] ]; then
47+
cp -rf "${HESTIA_INSTALL_DIR}/templates/web/nginx" "${WEBTPL}/"
48+
fi
49+
50+
# Migrate domains
51+
for user in $($BIN/v-list-sys-users plain); do
52+
echo "Migrating legacy multiphp domains for user: $user"
53+
for domain in $($BIN/v-list-web-domains $user plain |cut -f1); do
54+
echo "Processing domain: $domain"
55+
web_tpl="default"
56+
backend_tpl="$DEFAULT_BTPL"
57+
domain_tpl=$($BIN/v-list-web-domain $user $domain |grep "^TEMPLATE:" |awk '{print $2;}' );
58+
59+
if [ "$domain_tpl" = "PHP-56" ]; then
60+
backend_tpl="PHP-5_6"
61+
elif [ "$domain_tpl" = "PHP-70" ]; then
62+
backend_tpl="PHP-7_0"
63+
elif [ "$domain_tpl" = "PHP-71" ]; then
64+
backend_tpl="PHP-7_1"
65+
elif [ "$domain_tpl" = "PHP-72" ]; then
66+
backend_tpl="PHP-7_2"
67+
elif [ "$domain_tpl" = "PHP-73" ] || [ "$domain_tpl" = "default" ] || [ -z "$domain_tpl" ]; then
68+
backend_tpl="PHP-7_3"
69+
else
70+
# Custom domain template used
71+
echo "Domain is using a custom multiphp template (or non-multiphp one)"
72+
73+
web_tpl="$domain_tpl"
74+
if [ -f "${WEBTPL}/$WEB_SYSTEM/php-fpm/$web_tpl.tpl" ]; then
75+
# php-fpm backend folder allready has a template with the same name
76+
web_tpl="custom-$domain_tpl"
77+
fi
78+
79+
# Copy custom template to php-fpm backend folder
80+
mkdir -p "$WEBTPL/$WEB_SYSTEM/php-fpm"
81+
if [ -f "$WEBTPL/$WEB_SYSTEM/$domain_tpl.sh" ]; then
82+
cp "$WEBTPL/$WEB_SYSTEM/$domain_tpl.sh" "$WEBTPL/$WEB_SYSTEM/php-fpm/$web_tpl.sh"
83+
fi
84+
cp "$WEBTPL/$WEB_SYSTEM/$domain_tpl.tpl" "$WEBTPL/$WEB_SYSTEM/php-fpm/$web_tpl.tpl"
85+
cp "$WEBTPL/$WEB_SYSTEM/$domain_tpl.stpl" "$WEBTPL/$WEB_SYSTEM/php-fpm/$web_tpl.stpl"
86+
87+
88+
if [[ $(grep "unix:/" $WEBTPL/$WEB_SYSTEM/$domain_tpl.tpl |egrep -v "^\s*#" |tail -n1) \
89+
=~ unix:\/run\/php\/php([0-9]+\.[0-9]+)-fpm.+\.sock ]]; then
90+
91+
# Found a custom template that is based on official multiphp one
92+
backend_tpl="PHP-${BASH_REMATCH[1]/\./_}"
93+
echo "Custom multiphp template ($domain_tpl) compatible with backend: $backend_tpl"
94+
95+
# Remove multiphp switching script
96+
rm -f "$WEBTPL/$WEB_SYSTEM/php-fpm/$web_tpl.sh"
97+
98+
# Replace hardcoded php-fpm socket path with tpl variable, ignoring commented lines
99+
sed '/^[[:space:]]*#/!s/unix:.*;/%backend_lsnr%;/g' "$WEBTPL/$WEB_SYSTEM/php-fpm/$web_tpl.tpl"
100+
sed '/^[[:space:]]*#/!s/unix:.*;/%backend_lsnr%;/g' "$WEBTPL/$WEB_SYSTEM/php-fpm/$web_tpl.stpl"
101+
fi
102+
fi
103+
104+
echo "Parsed config: oldTPL=$domain_tpl newTPL:$web_tpl newBackTPL:$backend_tpl"
105+
$BIN/v-change-web-domain-tpl "$user" "$domain" "$web_tpl" "no"
106+
$BIN/v-change-web-domain-backend-tpl "$user" "$domain" "$backend_tpl" "no"
107+
echo -e "--done--\n"
108+
done
109+
done
110+
111+
# cleanup legacy multiphp templates
112+
for php_ver in $(ls /etc/php/); do
113+
[ ! -d "/etc/php/$php_ver/fpm/pool.d/" ] && continue
114+
echo "Remove legacy multiphp templates for: $php_ver"
115+
[ -f "$WEBTPL/$WEB_SYSTEM/PHP-${php_ver//.}.sh" ] && rm "$WEBTPL/$WEB_SYSTEM/PHP-${php_ver//.}.sh"
116+
[ -f "$WEBTPL/$WEB_SYSTEM/PHP-${php_ver//.}.tpl" ] && rm "$WEBTPL/$WEB_SYSTEM/PHP-${php_ver//.}.tpl"
117+
[ -f "$WEBTPL/$WEB_SYSTEM/PHP-${php_ver//.}.stpl" ] && rm "$WEBTPL/$WEB_SYSTEM/PHP-${php_ver//.}.stpl"
118+
done
119+
120+
# Remove default symlinks
121+
[ -f "$WEBTPL/$WEB_SYSTEM/default.sh" ] && rm "$WEBTPL/$WEB_SYSTEM/default.sh"
122+
[ -f "$WEBTPL/$WEB_SYSTEM/default.tpl" ] && rm "$WEBTPL/$WEB_SYSTEM/default.tpl"
123+
[ -f "$WEBTPL/$WEB_SYSTEM/default.stpl" ] && rm "$WEBTPL/$WEB_SYSTEM/default.stpl"
124+
125+
126+
$BIN/v-update-web-templates 'no'
127+
fi

install/upgrade/versions/latest.sh

Lines changed: 0 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -56,125 +56,3 @@ if [ -e $HESTIA/data/users/history.log ]; then
5656
rm -f $HESTIA/data/users/history.log
5757
fi
5858

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

Comments
 (0)