fup shell

master
Sergey Marinkevich 4 months ago
parent 40526b38bd
commit 11199635fd

@ -1,4 +1,4 @@
#!/bin/bash #/usr/bin/python3
import os import os
import sys import sys
@ -9,6 +9,7 @@ import configparser
import multiprocessing import multiprocessing
CONFIG_FILE = "/etc/butler.ini" CONFIG_FILE = "/etc/butler.ini"
SHELL_EXECUTABLE = '/bin/bash' # Гарантируем использование bash
# --- Функции, выполняющие действия --- # --- Функции, выполняющие действия ---
@ -21,14 +22,13 @@ def are_users_there(check_cmd, service_name):
try: try:
# shell=True позволяет использовать пайпы (|) и другие возможности shell # shell=True позволяет использовать пайпы (|) и другие возможности shell
# check=True бросит исключение CalledProcessError при ненулевом коде возврата # check=True бросит исключение CalledProcessError при ненулевом коде возврата
print(f"[{service_name}] run {check_cmd}.", flush=True)
subprocess.run( subprocess.run(
check_cmd, check_cmd,
shell=True, shell=True,
check=True, check=True,
stdout=subprocess.DEVNULL, stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
executable='/bin/bash' executable=SHELL_EXECUTABLE # Явно указываем bash
) )
return True return True
except (subprocess.CalledProcessError, FileNotFoundError): except (subprocess.CalledProcessError, FileNotFoundError):
@ -38,12 +38,12 @@ def are_users_there(check_cmd, service_name):
def server_shutdown(stop_cmd, service_name): def server_shutdown(stop_cmd, service_name):
print(f"[{service_name}] Stopping server...", flush=True) print(f"[{service_name}] Stopping server...", flush=True)
subprocess.run(stop_cmd, shell=True) subprocess.run(stop_cmd, shell=True, executable=SHELL_EXECUTABLE)
print(f"[{service_name}] Stop command sent.", flush=True) print(f"[{service_name}] Stop command sent.", flush=True)
def server_startup(start_cmd, service_name): def server_startup(start_cmd, service_name):
print(f"[{service_name}] Starting server...", flush=True) print(f"[{service_name}] Starting server...", flush=True)
subprocess.run(start_cmd, shell=True) subprocess.run(start_cmd, shell=True, executable=SHELL_EXECUTABLE)
print(f"[{service_name}] Start command sent.", flush=True) print(f"[{service_name}] Start command sent.", flush=True)
def wait_client(host, port, service_name): def wait_client(host, port, service_name):

Loading…
Cancel
Save