Merge pull request #1590 from master3395/v2.5.5-dev

V2.5.5 dev
This commit is contained in:
Master3395
2025-10-29 22:58:57 +01:00
committed by GitHub
2 changed files with 58 additions and 3 deletions

View File

@@ -267,6 +267,37 @@ class CronUtil:
except Exception as e:
print(f"-1,Error checking cron status: {str(e)}")
@staticmethod
def restartCronService():
"""
Restart the cron service to apply changes immediately.
Works across all distributions (Ubuntu/Debian/CentOS/AlmaLinux).
Returns:
tuple: (success_bool, error_message)
"""
try:
# Determine which cron service command to use based on distribution
distro = ProcessUtilities.decideDistro()
if distro == ProcessUtilities.centos or distro == ProcessUtilities.cent8:
# CentOS/AlmaLinux uses 'crond'
command = 'systemctl restart crond'
else:
# Ubuntu/Debian uses 'cron'
command = 'systemctl restart cron'
# Execute the restart command with root privileges
ProcessUtilities.executioner(command, 'root')
# Return success
return (True, None)
except BaseException as msg:
error_msg = f"Failed to restart cron service: {str(msg)}"
print(f"0,{error_msg}")
return (False, error_msg)
def main():

View File

@@ -4667,6 +4667,15 @@ context /cyberpanel_suspension_page.html {
CronUtil.CronPrem(0)
if output.find("1,") > -1:
# Restart cron service to apply changes immediately
restart_success, restart_error = CronUtil.restartCronService()
if not restart_success:
# Strict mode: return error response if restart fails
dic = {'getWebsiteCron': 0, 'error_message': f'Cron job modified but service restart failed: {restart_error}. Please manually restart cron service.'}
json_data = json.dumps(dic)
return HttpResponse(json_data)
data_ret = {"getWebsiteCron": 1,
"user": website.externalApp,
"cron": finalCron,
@@ -4708,6 +4717,15 @@ context /cyberpanel_suspension_page.html {
CronUtil.CronPrem(0)
if output.find("1,") > -1:
# Restart cron service to apply changes immediately
restart_success, restart_error = CronUtil.restartCronService()
if not restart_success:
# Strict mode: return error response if restart fails
dic = {'remCronbyLine': 0, 'error_message': f'Cron job removed but service restart failed: {restart_error}. Please manually restart cron service.'}
json_data = json.dumps(dic)
return HttpResponse(json_data)
data_ret = {"remCronbyLine": 1,
"user": website.externalApp,
"removeLine": output.split(',')[1],
@@ -4764,16 +4782,22 @@ context /cyberpanel_suspension_page.html {
execPath = execPath + " addNewCron --externalApp " + website.externalApp + " --finalCron '" + finalCron + "'"
output = ProcessUtilities.outputExecutioner(execPath, website.externalApp)
# Set proper permissions for Ubuntu/Debian
if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu or ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu20:
command = 'chmod 600 %s' % (cronPath)
ProcessUtilities.executioner(command)
command = 'systemctl restart cron'
ProcessUtilities.executioner(command)
CronUtil.CronPrem(0)
if output.find("1,") > -1:
# Restart cron service to apply changes immediately (all distributions)
restart_success, restart_error = CronUtil.restartCronService()
if not restart_success:
# Strict mode: return error response if restart fails
dic = {'addNewCron': 0, 'error_message': f'Cron job added but service restart failed: {restart_error}. Please manually restart cron service.'}
json_data = json.dumps(dic)
return HttpResponse(json_data)
data_ret = {"addNewCron": 1,
"user": website.externalApp,