All checks were successful
Deploy Beta (NATIVE) / deploy (push) Successful in 55s
68 lines
2 KiB
Python
68 lines
2 KiB
Python
import os
|
|
import subprocess
|
|
|
|
# Create symlink from /var/www/html/dolibarrbeta to the actual htdocs folder
|
|
symlink_path = '/var/www/html/dolibarrbeta'
|
|
target_path = '/home/ubuntu/dolibarrbeta/htdocs'
|
|
|
|
try:
|
|
if os.path.islink(symlink_path) or os.path.exists(symlink_path):
|
|
os.remove(symlink_path)
|
|
os.symlink(target_path, symlink_path)
|
|
print(f"Created symlink {symlink_path} -> {target_path}")
|
|
except Exception as e:
|
|
print(f"Symlink creation message: {e}")
|
|
|
|
def remove_location_block(content, path):
|
|
search_str = f"location {path}"
|
|
start_idx = content.find(search_str)
|
|
if start_idx == -1:
|
|
return content
|
|
|
|
brace_start = content.find("{", start_idx)
|
|
if brace_start == -1:
|
|
return content
|
|
|
|
count = 1
|
|
i = brace_start + 1
|
|
while i < len(content) and count > 0:
|
|
if content[i] == '{':
|
|
count += 1
|
|
elif content[i] == '}':
|
|
count -= 1
|
|
i += 1
|
|
|
|
return content[:start_idx] + content[i:]
|
|
|
|
filepath = '/etc/nginx/sites-available/default'
|
|
|
|
if os.path.exists(filepath):
|
|
content = open(filepath).read()
|
|
|
|
# Strip any existing /dolibarrbeta block
|
|
content = remove_location_block(content, '/dolibarrbeta')
|
|
|
|
# Insert the new correct root-based location block with increased timeout
|
|
idx = content.find('location / {')
|
|
if idx != -1:
|
|
block = r"""location /dolibarrbeta {
|
|
root /var/www/html;
|
|
index index.php;
|
|
try_files $uri $uri/ /dolibarrbeta/index.php?$args;
|
|
|
|
location ~ \.php$ {
|
|
include fastcgi_params;
|
|
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
|
fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
|
|
fastcgi_read_timeout 300;
|
|
}
|
|
}
|
|
|
|
"""
|
|
content = content[:idx] + block + content[idx:]
|
|
open('/tmp/default', 'w').write(content)
|
|
print("Nginx config generated at /tmp/default")
|
|
else:
|
|
print("Error: Could not find 'location / {' in Nginx config")
|
|
else:
|
|
print(f"Error: {filepath} not found")
|