refs #437 Adds uninstall option to daemon
parent
636c6fb2c5
commit
361c892acb
|
@ -1,8 +1,9 @@
|
||||||
|
import os
|
||||||
import socket
|
import socket
|
||||||
import json
|
import json
|
||||||
import subprocess
|
import subprocess
|
||||||
import logging
|
import logging
|
||||||
import os
|
import stat
|
||||||
|
|
||||||
# Configuración de logging
|
# Configuración de logging
|
||||||
logging.basicConfig(level=logging.INFO, filename='/var/log/oglive_daemon.log', filemode='a', format='%(asctime)s - %(levelname)s - %(message)s')
|
logging.basicConfig(level=logging.INFO, filename='/var/log/oglive_daemon.log', filemode='a', format='%(asctime)s - %(levelname)s - %(message)s')
|
||||||
|
@ -10,31 +11,33 @@ logging.basicConfig(level=logging.INFO, filename='/var/log/oglive_daemon.log', f
|
||||||
def handle_command(command):
|
def handle_command(command):
|
||||||
action = command.get('action')
|
action = command.get('action')
|
||||||
args = command.get('args', [])
|
args = command.get('args', [])
|
||||||
|
cleaned_args = [arg.strip('\'"') for arg in args]
|
||||||
|
|
||||||
if action in ['install', 'download', 'uninstall', 'show', 'check']:
|
logging.info(f'Handling command: {action} with args: {cleaned_args}')
|
||||||
try:
|
|
||||||
logging.info(f'Handling command: {action} with args: {args}')
|
try:
|
||||||
cleaned_args = [arg.strip('\'"') for arg in args] # Limpiar comillas
|
if action in ['config', 'install', 'download', 'show', 'check', 'uninstall']:
|
||||||
command_to_run = ['sudo', '/opt/ogboot/bin/oglivecli', action] + cleaned_args
|
command_to_run = ['sudo', '/opt/ogboot/bin/oglivecli', action] + cleaned_args
|
||||||
|
logging.info(f'Running command: {" ".join(command_to_run)}')
|
||||||
process = subprocess.Popen(command_to_run, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
process = subprocess.Popen(command_to_run, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
||||||
|
|
||||||
stdout, stderr = process.communicate()
|
stdout, stderr = process.communicate()
|
||||||
|
logging.info(f'Command output: {stdout}')
|
||||||
if process.returncode == 0:
|
if process.returncode == 0:
|
||||||
logging.info(f'Command executed successfully: {stdout}')
|
return {"success": True, "output": stdout.strip()}
|
||||||
return {"success": True, "output": stdout}
|
|
||||||
else:
|
else:
|
||||||
logging.error(f'Command failed with error: {stderr}')
|
|
||||||
return {"success": False, "error": stderr.strip()}
|
return {"success": False, "error": stderr.strip()}
|
||||||
except Exception as e:
|
else:
|
||||||
logging.error(f'Failed to handle command {action}: {e}')
|
return {"success": False, "error": "Unknown command"}
|
||||||
return {"success": False, "error": str(e)}
|
except Exception as e:
|
||||||
else:
|
logging.error(f'Error handling command {action}: {e}')
|
||||||
logging.error(f'Unknown command action: {action}')
|
return {"success": False, "error": str(e)}
|
||||||
return {"success": False, "error": "Unknown command action"}
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
socket_path = '/tmp/oglive_daemon.sock'
|
# Crea el directorio si no existe
|
||||||
|
if not os.path.exists('/var/run/oglive'):
|
||||||
|
os.makedirs('/var/run/oglive', exist_ok=True)
|
||||||
|
|
||||||
|
socket_path = '/var/run/oglive/oglive_daemon.sock'
|
||||||
|
|
||||||
# Elimina el socket si existe
|
# Elimina el socket si existe
|
||||||
if os.path.exists(socket_path):
|
if os.path.exists(socket_path):
|
||||||
|
@ -42,6 +45,10 @@ def main():
|
||||||
|
|
||||||
server = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
server = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||||
server.bind(socket_path)
|
server.bind(socket_path)
|
||||||
|
|
||||||
|
# Establece los permisos del socket
|
||||||
|
os.chmod(socket_path, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO) # Permisos para todos los usuarios
|
||||||
|
|
||||||
server.listen()
|
server.listen()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -53,7 +60,6 @@ def main():
|
||||||
data = conn.recv(1024)
|
data = conn.recv(1024)
|
||||||
if not data:
|
if not data:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
command = json.loads(data.decode('utf-8'))
|
command = json.loads(data.decode('utf-8'))
|
||||||
logging.info(f'Received command: {command}')
|
logging.info(f'Received command: {command}')
|
||||||
|
|
Loading…
Reference in New Issue