🚀 Auto-deploy: BotVPS atualizado em 28/03/2026 19:27:25
This commit is contained in:
16
tools.py
16
tools.py
@@ -8,23 +8,35 @@ import json
|
|||||||
def run_bash_command(command: str) -> str:
|
def run_bash_command(command: str) -> str:
|
||||||
"""Executa um comando bash na VPS e retorna a saída."""
|
"""Executa um comando bash na VPS e retorna a saída."""
|
||||||
try:
|
try:
|
||||||
|
# Garante caminhos comuns no PATH para execução via PM2/Containers
|
||||||
|
custom_env = os.environ.copy()
|
||||||
|
paths = ["/usr/local/bin", "/root/.cargo/bin", "/usr/bin", "/bin"]
|
||||||
|
current_path = custom_env.get("PATH", "")
|
||||||
|
for p in paths:
|
||||||
|
if p not in current_path:
|
||||||
|
current_path = f"{p}:{current_path}"
|
||||||
|
custom_env["PATH"] = current_path
|
||||||
|
|
||||||
# Executa comando de forma segura dentro da VPS
|
# Executa comando de forma segura dentro da VPS
|
||||||
result = subprocess.run(
|
result = subprocess.run(
|
||||||
command,
|
command,
|
||||||
shell=True,
|
shell=True,
|
||||||
capture_output=True,
|
capture_output=True,
|
||||||
text=True,
|
text=True,
|
||||||
timeout=120 # Aumentado para comandos mais pesados
|
timeout=120,
|
||||||
|
env=custom_env
|
||||||
)
|
)
|
||||||
|
|
||||||
output = result.stdout.strip()
|
output = result.stdout.strip()
|
||||||
error = result.stderr.strip()
|
error = result.stderr.strip()
|
||||||
|
|
||||||
# Se encontrou algo no stdout, retornamos o que achou mesmo com erro (ex: find com permissão negada em algumas pastas)
|
# Se encontrou algo no stdout, retornamos o que achou mesmo com erro
|
||||||
if output:
|
if output:
|
||||||
return output
|
return output
|
||||||
|
|
||||||
if result.returncode != 0:
|
if result.returncode != 0:
|
||||||
|
if result.returncode == 127:
|
||||||
|
return f"ERRO (127): Comando não encontrado. Verifique se o alias ou binário está no PATH. (Comando: {command})"
|
||||||
return f"ERRO ({result.returncode}): {error if error else 'Nada no stderr'}"
|
return f"ERRO ({result.returncode}): {error if error else 'Nada no stderr'}"
|
||||||
|
|
||||||
return "Sucesso (vazio)"
|
return "Sucesso (vazio)"
|
||||||
|
|||||||
11
tools_v2.py
11
tools_v2.py
@@ -16,7 +16,16 @@ def run_bash(command: str, timeout: int = 120) -> Dict:
|
|||||||
# Auto-moderniza docker-compose
|
# Auto-moderniza docker-compose
|
||||||
command = command.replace("docker-compose", "docker compose")
|
command = command.replace("docker-compose", "docker compose")
|
||||||
try:
|
try:
|
||||||
result = subprocess.run(command, shell=True, capture_output=True, text=True, timeout=timeout)
|
# Garante caminhos comuns no PATH para execução via PM2/Containers
|
||||||
|
custom_env = os.environ.copy()
|
||||||
|
paths = ["/usr/local/bin", "/root/.cargo/bin", "/usr/bin", "/bin"]
|
||||||
|
current_path = custom_env.get("PATH", "")
|
||||||
|
for p in paths:
|
||||||
|
if p not in current_path:
|
||||||
|
current_path = f"{p}:{current_path}"
|
||||||
|
custom_env["PATH"] = current_path
|
||||||
|
|
||||||
|
result = subprocess.run(command, shell=True, capture_output=True, text=True, timeout=timeout, env=custom_env)
|
||||||
return {
|
return {
|
||||||
"success": result.returncode == 0,
|
"success": result.returncode == 0,
|
||||||
"output": (result.stdout or result.stderr).strip() or "Sucesso"
|
"output": (result.stdout or result.stderr).strip() or "Sucesso"
|
||||||
|
|||||||
Reference in New Issue
Block a user