Permanent fix: ensure all new child domains get correct log configuration

- Fixed perHostDomainConf() to replace {virtualHostName} placeholder in olsChildConf template
- Updated lswsChildConf template to use master domain log directory
- Updated lswsRediConfChild and lswsRediConfChildWWW templates to use master domain log directory
- Added automatic log directory and log file creation for child domains during creation
- Log files are now created at /home/{masterDomain}/logs/{childDomain}.{access|error}_log
- Ensures all newly created sub-domains automatically have separate log files from the start

This permanent fix ensures that when child domains are created:
1. VHost config uses correct log paths pointing to master domain's log directory
2. Log directory is created if it doesn't exist
3. Separate log files are created for each child domain with proper permissions
4. Works for both OpenLiteSpeed (OLS) and LiteSpeed Enterprise (LSWS) configurations

Fixes the root cause so all future child domain creations will have correct log configuration automatically.
This commit is contained in:
master3395
2026-01-19 18:46:16 +01:00
parent fdf5b2abcb
commit 2b8377da7f
2 changed files with 77 additions and 3 deletions

View File

@@ -1075,6 +1075,7 @@ class vhost:
currentConf = vhostConfs.olsChildConf
currentConf = currentConf.replace('{path}', path)
currentConf = currentConf.replace('{masterDomain}', masterDomain)
currentConf = currentConf.replace('{virtualHostName}', domain)
currentConf = currentConf.replace('{adminEmails}', administratorEmail)
currentConf = currentConf.replace('{externalApp}', externalApp)
currentConf = currentConf.replace('{externalAppMaster}', virtualHostUser)
@@ -1087,6 +1088,30 @@ class vhost:
currentConf = currentConf.replace('{open_basedir}', 'php_admin_value open_basedir "/tmp:$VH_ROOT"')
else:
currentConf = currentConf.replace('{open_basedir}', '')
# Ensure log directory exists in master domain's home directory
masterLogDir = f"/home/{masterDomain}/logs"
try:
if not os.path.exists(masterLogDir):
os.makedirs(masterLogDir, exist_ok=True)
command = f"chown -R {virtualHostUser}:{virtualHostUser} {masterLogDir}"
ProcessUtilities.executioner(command)
# Create empty log files for the child domain
error_log_path = f"{masterLogDir}/{domain}.error_log"
access_log_path = f"{masterLogDir}/{domain}.access_log"
for log_path in [error_log_path, access_log_path]:
if not os.path.exists(log_path):
with open(log_path, 'w') as f:
f.write('')
command = f"chown {virtualHostUser}:{virtualHostUser} {log_path}"
ProcessUtilities.executioner(command)
command = f"chmod 644 {log_path}"
ProcessUtilities.executioner(command)
except Exception as logErr:
logging.CyberCPLogFileWriter.writeToFile(
f'Error creating log files for child domain {domain}: {str(logErr)}')
confFile = open(vhFile, "w+")
confFile.write(currentConf)
@@ -1116,6 +1141,30 @@ class vhost:
confFile.write(currentConf)
confFile.close()
# Ensure log directory exists in master domain's home directory and create log files
masterLogDir = f"/home/{masterDomain}/logs"
try:
if not os.path.exists(masterLogDir):
os.makedirs(masterLogDir, exist_ok=True)
command = f"chown -R {virtualHostUser}:{virtualHostUser} {masterLogDir}"
ProcessUtilities.executioner(command)
# Create empty log files for the child domain
error_log_path = f"{masterLogDir}/{domain}.error_log"
access_log_path = f"{masterLogDir}/{domain}.access_log"
for log_path in [error_log_path, access_log_path]:
if not os.path.exists(log_path):
with open(log_path, 'w') as f:
f.write('')
command = f"chown {virtualHostUser}:{virtualHostUser} {log_path}"
ProcessUtilities.executioner(command)
command = f"chmod 644 {log_path}"
ProcessUtilities.executioner(command)
except Exception as logErr:
logging.CyberCPLogFileWriter.writeToFile(
f'Error creating log files for child domain {domain}: {str(logErr)}')
else:
@@ -1134,6 +1183,28 @@ class vhost:
command = 'redis-cli set %s' % (currentConf)
ProcessUtilities.executioner(command)
# Ensure log directory exists in master domain's home directory and create log files
masterLogDir = f"/home/{masterDomain}/logs"
try:
if not os.path.exists(masterLogDir):
os.makedirs(masterLogDir, exist_ok=True)
command = f"chown -R {virtualHostUser}:{virtualHostUser} {masterLogDir}"
ProcessUtilities.executioner(command)
# Create empty log files for the child domain (non-www)
access_log_path = f"{masterLogDir}/{domain}.access_log"
if not os.path.exists(access_log_path):
with open(access_log_path, 'w') as f:
f.write('')
command = f"chown {virtualHostUser}:{virtualHostUser} {access_log_path}"
ProcessUtilities.executioner(command)
command = f"chmod 644 {access_log_path}"
ProcessUtilities.executioner(command)
except Exception as logErr:
logging.CyberCPLogFileWriter.writeToFile(
f'Error creating log files for child domain {domain} (redis non-www): {str(logErr)}')
## www
@@ -1150,6 +1221,9 @@ class vhost:
command = 'redis-cli set %s' % (currentConf)
ProcessUtilities.executioner(command)
# Note: Log files already created for non-www version above
# The www version shares the same log files
except BaseException as msg:
logging.CyberCPLogFileWriter.writeToFile(

View File

@@ -204,7 +204,7 @@ context /.well-known/acme-challenge {
SuexecUserGroup {externalApp} {externalApp}
DocumentRoot {path}
Alias /.well-known/acme-challenge /usr/local/lsws/Example/html/.well-known/acme-challenge
CustomLog /home/{virtualHostName}/logs/{virtualHostName}.access_log combined
CustomLog /home/{masterDomain}/logs/{virtualHostName}.access_log combined
AddHandler application/x-httpd-php{php} .php .php7 .phtml
<IfModule LiteSpeed>
CacheRoot lscache
@@ -474,7 +474,7 @@ pm.max_spare_servers = {pmMaxSpareServers}
"phpVersion": {php},
"custom_conf": {
ServerAdmin {administratorEmail}
CustomLog /home/{virtualHostName}/logs/{virtualHostName}.access_log combined
CustomLog /home/{masterDomain}/logs/{virtualHostName}.access_log combined
<IfModule LiteSpeed>
CacheRoot /home/{masterDomain}/lscache
</IfModule>
@@ -489,7 +489,7 @@ pm.max_spare_servers = {pmMaxSpareServers}
"phpVersion": {php},
"custom_conf": {
ServerAdmin {administratorEmail}
CustomLog /home/{virtualHostName}/logs/{virtualHostName}.access_log combined
CustomLog /home/{masterDomain}/logs/{virtualHostName}.access_log combined
<IfModule LiteSpeed>
CacheRoot /home/{masterDomain}/lscache
</IfModule>