refs #477 Adds exceptions to oglive daemon conf

ogboot_installer
Luis Gerardo Romero Garcia 2024-07-02 12:02:11 +02:00
parent e8d30f62e3
commit 72adbf37cf
1 changed files with 38 additions and 17 deletions

View File

@ -881,24 +881,45 @@ def setup_nginx():
exit(1)
def install_oglive_daemon():
INSTALL_TARGET = "/opt/ogboot"
DAEMON_SCRIPT_SRC = os.path.join(WORKDIR, "oglive_daemon.py")
DAEMON_SCRIPT_DEST = os.path.join(INSTALL_TARGET, "bin", "oglive_daemon.py")
SERVICE_FILE_SRC = os.path.join(WORKDIR, "ogboot/etc/oglive_daemon.service")
SERVICE_FILE_DEST = "/etc/systemd/system/oglive_daemon.service"
try:
DAEMON_SCRIPT_SRC = os.path.join(WORKDIR, "ogboot/bin/oglive_daemon.py")
DAEMON_SCRIPT_DEST = os.path.join(INSTALL_TARGET, "bin", "oglive_daemon.py")
SERVICE_FILE_SRC = os.path.join(WORKDIR, "ogboot/etc/oglive_daemon.service")
SERVICE_FILE_DEST = "/etc/systemd/system/oglive_daemon.service"
shutil.copyfile(DAEMON_SCRIPT_SRC, DAEMON_SCRIPT_DEST)
logger.info(f"Copied {DAEMON_SCRIPT_SRC} to {DAEMON_SCRIPT_DEST}")
os.chmod(DAEMON_SCRIPT_DEST, 0o755)
logger.info(f"Set executable permissions for {DAEMON_SCRIPT_DEST}")
shutil.copyfile(SERVICE_FILE_SRC, SERVICE_FILE_DEST)
logger.info(f"Copied {SERVICE_FILE_SRC} to {SERVICE_FILE_DEST}")
subprocess.run(["systemctl", "daemon-reload"], check=True)
logger.info("Reloaded systemd daemon")
subprocess.run(["systemctl", "enable", "oglive_daemon.service"], check=True)
logger.info("Enabled oglive_daemon service")
subprocess.run(["systemctl", "start", "oglive_daemon.service"], check=True)
logger.info("Started oglive_daemon service")
# Crear directorio de destino si no existe
os.makedirs(os.path.dirname(DAEMON_SCRIPT_DEST), exist_ok=True)
# Copiar el script del demonio al directorio de destino
shutil.copyfile(DAEMON_SCRIPT_SRC, DAEMON_SCRIPT_DEST)
logger.info(f"Copied {DAEMON_SCRIPT_SRC} to {DAEMON_SCRIPT_DEST}")
# Hacer el script ejecutable
os.chmod(DAEMON_SCRIPT_DEST, 0o755)
logger.info(f"Set executable permissions for {DAEMON_SCRIPT_DEST}")
# Copiar el archivo de servicio de systemd
shutil.copyfile(SERVICE_FILE_SRC, SERVICE_FILE_DEST)
logger.info(f"Copied {SERVICE_FILE_SRC} to {SERVICE_FILE_DEST}")
# Recargar systemd para reconocer el nuevo servicio
subprocess.run(["systemctl", "daemon-reload"], check=True)
logger.info("Reloaded systemd daemon")
# Habilitar el servicio para que arranque al inicio
subprocess.run(["systemctl", "enable", "oglive_daemon.service"], check=True)
logger.info("Enabled oglive_daemon service")
# Arrancar el servicio
subprocess.run(["systemctl", "start", "oglive_daemon.service"], check=True)
logger.info("Started oglive_daemon service")
except (shutil.Error, OSError) as e:
logger.error(f"File operation error: {e}")
except subprocess.CalledProcessError as e:
logger.error(f"Subprocess error: {e}")
except Exception as e:
logger.error(f"An unexpected error occurred: {e}")
###############################################################################
###:::::::::::::::::::::::::::::::: MAIN :::::::::::::::::::::::::::::::::::###