.
This commit is contained in:
@@ -131,20 +131,17 @@ async def restart_service():
|
||||
async def delayed_restart():
|
||||
await asyncio.sleep(settings.restart_delay)
|
||||
try:
|
||||
result = await asyncio.create_subprocess_exec(
|
||||
"sudo", "supervisorctl", "restart", "llm-api-mcphost",
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE
|
||||
# Use subprocess.Popen with start_new_session=True
|
||||
import subprocess
|
||||
process = subprocess.Popen(
|
||||
["sudo", "supervisorctl", "restart", "llm-api-mcphost", "&&", "/usr/local/bin/gotify", "'mcphost service restarted'"],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
start_new_session=True # This detaches the process
|
||||
)
|
||||
stdout, stderr = await result.communicate()
|
||||
|
||||
if result.returncode != 0:
|
||||
logger.error(
|
||||
f"Failed to restart service: return_code={result.returncode}, stderr={stderr.decode()}, stdout={stdout.decode()}")
|
||||
else:
|
||||
logger.info(f"Successfully restarted service: {stdout.decode()}")
|
||||
logger.info("Restart command initiated (detached)")
|
||||
except Exception as e:
|
||||
logger.error(f"Error restarting service: {str(e)}")
|
||||
logger.error(f"Error initiating restart: {str(e)}")
|
||||
|
||||
# Schedule the restart without waiting for it
|
||||
asyncio.create_task(delayed_restart())
|
||||
|
||||
Reference in New Issue
Block a user