Fixes
This commit is contained in:
@@ -62,7 +62,7 @@ def log_migrate_stage(stage)
|
||||
yield
|
||||
# Record the successful stage
|
||||
File.open(log_file, 'a') { |f| f.puts stage }
|
||||
hestia_print_error_message_to_cli "Stage #{stage} completed."
|
||||
hestia_print_info_message_to_cli "Stage #{stage} completed."
|
||||
rescue => e
|
||||
hestia_print_error_message_to_cli "Stage #{stage} failed: #{e.message}"
|
||||
exit 1
|
||||
@@ -165,10 +165,12 @@ when :migratenginx
|
||||
# Find all files under the nginx-system directory
|
||||
nginx_conf_dir = '/usr/local/hestia/nginx-system/etc/nginx'
|
||||
Dir.glob(File.join(nginx_conf_dir, '**', '*')).each do |path|
|
||||
hestia_print_info_message_to_cli "stage 4 processing file #{path}"
|
||||
next if File.directory?(path)
|
||||
content = File.read(path)
|
||||
new_content = content.gsub(/(?<!\/usr\/local\/hestia\/nginx-system)\/etc\/nginx/, '/usr/local/hestia/nginx-system/etc/nginx')
|
||||
if new_content != content
|
||||
hestia_print_info_message_to_cli "Changed path to config in file #{path}"
|
||||
File.open(path, 'w') { |f| f.write(new_content) }
|
||||
end
|
||||
end
|
||||
@@ -182,12 +184,13 @@ when :migratenginx
|
||||
|
||||
# Find and replace port in all .conf files
|
||||
Dir.glob(File.join(nginx_conf_dir, '**', '*.conf')).each do |conf_file|
|
||||
hestia_print_info_message_to_cli "stage 5 processing file #{conf_file}"
|
||||
content = File.read(conf_file)
|
||||
modified = false
|
||||
|
||||
# Replace HTTP port pattern: listen <IP>:#{$PROXY_PORT} [flags];
|
||||
# Matches: listen 192.168.3.81:80; or listen 192.168.3.81:80 default_server;
|
||||
new_content = content.gsub(/(?<![0-9a-fA-F:])\d{1,3}(\.\d{1,3}){3}:\#\{$PROXY_PORT\}\s*(.*)/i) do |match|
|
||||
new_content = content.gsub(/(?<![0-9a-fA-F:])\d{1,3}(\.\d{1,3}){3}:#{$PROXY_PORT}\s*(.*)/i) do |match|
|
||||
modified = true
|
||||
ip_part = $&.split(':')[0] # Get IP address part
|
||||
remaining = $POSTMATCH.strip # Get any additional flags (default_server, etc.)
|
||||
@@ -201,7 +204,7 @@ when :migratenginx
|
||||
|
||||
# If first substitution didn't match, try simpler pattern for ports without IP
|
||||
if new_content == content
|
||||
new_content = content.gsub(/#\{$PROXY_PORT\}\s*(ssl\s*)?;?\s*$/i) do |match|
|
||||
new_content = content.gsub(/#{$PROXY_PORT}\s*(ssl\s*)?;?\s*$/i) do |match|
|
||||
modified = true
|
||||
flags = $1 || ''
|
||||
";#{proxy_port}#{flags}"
|
||||
@@ -210,7 +213,7 @@ when :migratenginx
|
||||
|
||||
# Replace SSL port pattern: listen <IP>:#{$PROXY_SSL_PORT} ssl;
|
||||
if new_content == content
|
||||
new_content = content.gsub(/(?<![0-9a-fA-F:])\d{1,3}(\.\d{1,3}){3}:\#\{$PROXY_SSL_PORT\}\s+ssl\s*;?\s*$/i) do |match|
|
||||
new_content = content.gsub(/(?<![0-9a-fA-F:])\d{1,3}(\.\d{1,3}){3}:#{$PROXY_SSL_PORT}\s+ssl\s*;?\s*$/i) do |match|
|
||||
modified = true
|
||||
ip_part = $&.split(':')[0] # Get IP address part
|
||||
"#{ip_part}:#{proxy_ssl_port} ssl;"
|
||||
@@ -219,8 +222,8 @@ when :migratenginx
|
||||
|
||||
# Simple fallback: replace the port variable values directly
|
||||
if new_content == content
|
||||
new_content = content.gsub("#\{$PROXY_PORT\}", proxy_port)
|
||||
new_content = new_content.gsub("#\{$PROXY_SSL_PORT\}", proxy_ssl_port)
|
||||
new_content = content.gsub("#{$PROXY_PORT}", proxy_port)
|
||||
new_content = new_content.gsub("#{$PROXY_SSL_PORT}", proxy_ssl_port)
|
||||
modified = true if new_content != content
|
||||
end
|
||||
|
||||
@@ -230,34 +233,6 @@ when :migratenginx
|
||||
hestia_print_info_message_to_cli " Updated: #{conf_file}"
|
||||
end
|
||||
end
|
||||
|
||||
# Also update default.conf specifically if it exists
|
||||
default_conf = File.join(nginx_conf_dir, 'conf.d', 'default.conf')
|
||||
if File.exist?(default_conf)
|
||||
content = File.read(default_conf)
|
||||
modified = false
|
||||
|
||||
# Replace HTTP port in default.conf
|
||||
new_content = content.gsub(/#\{$PROXY_PORT\}\s*(default_server\s*)?;/i) do |match|
|
||||
modified = true
|
||||
flags = $1 || ''
|
||||
"#{proxy_port}#{flags};"
|
||||
end
|
||||
|
||||
# Replace SSL port in default.conf
|
||||
if new_content == content || new_content.include?("#{$PROXY_SSL_PORT}")
|
||||
new_content = content.gsub(/#\{$PROXY_SSL_PORT\}\s+default_server\s+ssl\s*;?\s*$/i) do |match|
|
||||
modified = true
|
||||
"#{proxy_ssl_port} default_server ssl;"
|
||||
end
|
||||
end
|
||||
|
||||
# Write changes if modified
|
||||
if modified
|
||||
File.open(default_conf, 'w') { |f| f.write(new_content) }
|
||||
hestia_print_info_message_to_cli " Updated: #{default_conf}"
|
||||
end
|
||||
end
|
||||
end
|
||||
log_migrate_stage('stage6') do
|
||||
hestia_change_sys_config_value("PROXY_PORT", "8078")
|
||||
|
||||
Reference in New Issue
Block a user