LR 0.4.9-dev: fixed self restore wstunnels; improvede webservice module disabling procedure.
Change-Id: I34f68e0ea490e793dd62d52e493925329dbce73b
This commit is contained in:
parent
f2d6f42457
commit
8cc42f2731
|
@ -24,6 +24,7 @@ LOG = logging.getLogger(__name__)
|
|||
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import time
|
||||
|
||||
|
@ -251,6 +252,62 @@ class ProxyManager(Proxy.Proxy):
|
|||
|
||||
return json.dumps(nginxMsg)
|
||||
|
||||
def _proxyDisableWebService(self):
|
||||
|
||||
nginxMsg = {}
|
||||
|
||||
try:
|
||||
|
||||
# NGINX clean up
|
||||
try:
|
||||
|
||||
nginx_path = "/etc/nginx/conf.d/"
|
||||
|
||||
shutil.rmtree(
|
||||
nginx_path,
|
||||
ignore_errors=False,
|
||||
onerror=None
|
||||
)
|
||||
LOG.debug("--> nginx conf.d path deleted")
|
||||
|
||||
os.makedirs(nginx_path, mode=0o755)
|
||||
LOG.debug("--> nginx conf.d path re-created")
|
||||
|
||||
except Exception as err:
|
||||
message = "Error removing nginx conf.d folder: " + str(err)
|
||||
LOG.warning(" - " + message)
|
||||
|
||||
# Letsencrypt clean up
|
||||
try:
|
||||
|
||||
le_path = "/etc/letsencrypt/"
|
||||
|
||||
shutil.rmtree(
|
||||
le_path,
|
||||
ignore_errors=False,
|
||||
onerror=None
|
||||
)
|
||||
|
||||
except Exception as err:
|
||||
message = "Error removing letsencrypt folder: " + str(err)
|
||||
LOG.warning(" - " + message)
|
||||
|
||||
time.sleep(3)
|
||||
|
||||
# NGINX reload
|
||||
self._proxyReload_proxyReload()
|
||||
|
||||
nginxMsg['result'] = "SUCCESS"
|
||||
nginxMsg['message'] = "Webservice module disabled."
|
||||
LOG.info("--> " + nginxMsg['message'])
|
||||
|
||||
except Exception as err:
|
||||
nginxMsg['log'] = "NGINX DNS disabling error: " + str(err)
|
||||
nginxMsg['code'] = ""
|
||||
LOG.warning("--> " + nginxMsg['log'])
|
||||
|
||||
return json.dumps(nginxMsg)
|
||||
|
||||
def _exposeWebservice(self, board_dns, service_dns, local_port, dns_list):
|
||||
|
||||
nginxMsg = {}
|
||||
|
|
|
@ -27,6 +27,7 @@ import time
|
|||
|
||||
import threading
|
||||
|
||||
import copy
|
||||
from datetime import datetime
|
||||
from random import randint
|
||||
from threading import Thread
|
||||
|
@ -129,7 +130,7 @@ class ServiceManager(Module.Module):
|
|||
s_conf = self._loadServicesConf()
|
||||
|
||||
global WS_LIST
|
||||
WS_LIST = s_conf
|
||||
WS_LIST = copy.deepcopy(s_conf)
|
||||
|
||||
if s_conf == None:
|
||||
|
||||
|
@ -307,7 +308,7 @@ class ServiceManager(Module.Module):
|
|||
s_conf = self._loadServicesConf()
|
||||
|
||||
global WS_LIST
|
||||
WS_LIST = s_conf
|
||||
WS_LIST = copy.deepcopy(s_conf)
|
||||
|
||||
if s_conf == None:
|
||||
|
||||
|
@ -770,16 +771,22 @@ class ServiceManager(Module.Module):
|
|||
print("WSTUN start event:")
|
||||
|
||||
cmd_print = 'WSTUN exec: ' + str(CONF.services.wstun_bin) \
|
||||
+ opt_reverse + ' ' + self.wstun_url
|
||||
+ " " + opt_reverse + ' ' + self.wstun_url
|
||||
print(" - " + str(cmd_print))
|
||||
LOG.debug(cmd_print)
|
||||
|
||||
# WSTUN MON
|
||||
# #############################################################
|
||||
|
||||
global WS_LIST
|
||||
WS_LIST['services'][s_uuid]['pid'] = wstun.pid
|
||||
# print("------> WS_LIST: " + str(WS_LIST))
|
||||
try:
|
||||
global WS_LIST
|
||||
WS_LIST['services'][s_uuid] = {}
|
||||
WS_LIST['services'][s_uuid]['pid'] = wstun.pid
|
||||
WS_LIST['services'][s_uuid]['updated_at'] = \
|
||||
datetime.now().strftime('%Y-%m-%dT%H:%M:%S.%f')
|
||||
print("(add)------> WS_LIST: " + str(WS_LIST))
|
||||
except Exception as err:
|
||||
LOG.error("Error WS_LIST: " + str(err))
|
||||
|
||||
try:
|
||||
if event != "enable":
|
||||
|
@ -846,7 +853,7 @@ class ServiceManager(Module.Module):
|
|||
if (event != "boot"):
|
||||
print("WSTUN start event:")
|
||||
|
||||
cmd_print = 'WSTUN exec: ' + str(CONF.services.wstun_bin) \
|
||||
cmd_print = 'WSTUN exec: ' + str(CONF.services.wstun_bin) + " " \
|
||||
+ opt_reverse + ' ' + self.wstun_url
|
||||
print(" - " + str(cmd_print))
|
||||
LOG.debug(cmd_print)
|
||||
|
@ -855,8 +862,11 @@ class ServiceManager(Module.Module):
|
|||
# #############################################################
|
||||
|
||||
global WS_LIST
|
||||
WS_LIST['services'][s_uuid] = {}
|
||||
WS_LIST['services'][s_uuid]['pid'] = wstun.pid
|
||||
# print("------> WS_LIST: " + str(WS_LIST))
|
||||
WS_LIST['services'][s_uuid]['updated_at'] = \
|
||||
datetime.now().strftime('%Y-%m-%dT%H:%M:%S.%f')
|
||||
print("(add)------> WS_LIST: " + str(WS_LIST))
|
||||
|
||||
wsmon = Thread(
|
||||
target=self._wstunMon,
|
||||
|
@ -874,17 +884,6 @@ class ServiceManager(Module.Module):
|
|||
|
||||
return wstun
|
||||
|
||||
async def ServicesStatus(self, req_id):
|
||||
rpc_name = utils.getFuncName()
|
||||
LOG.info("RPC " + rpc_name + " CALLED [req_id: " + str(req_id) + "]")
|
||||
|
||||
thr_list = str(threading.enumerate())
|
||||
# print(thr_list + "\n" + str(WS_MON_LIST))
|
||||
|
||||
w_msg = WM.WampSuccess(thr_list)
|
||||
|
||||
return w_msg.serialize()
|
||||
|
||||
def _updateServiceConf(self, s_conf, s_uuid, output=True):
|
||||
|
||||
if s_conf == "":
|
||||
|
@ -919,6 +918,17 @@ class ServiceManager(Module.Module):
|
|||
'cp ' + s_conf_FILE + ' ' + s_conf_FILE + '.bkp'
|
||||
)
|
||||
|
||||
async def ServicesStatus(self, req_id):
|
||||
rpc_name = utils.getFuncName()
|
||||
LOG.info("RPC " + rpc_name + " CALLED [req_id: " + str(req_id) + "]")
|
||||
|
||||
thr_list = str(threading.enumerate())
|
||||
# print(thr_list + "\n" + str(WS_MON_LIST))
|
||||
|
||||
w_msg = WM.WampSuccess(thr_list)
|
||||
|
||||
return w_msg.serialize()
|
||||
|
||||
async def ServiceEnable(self, req_id, service, public_port):
|
||||
|
||||
rpc_name = utils.getFuncName()
|
||||
|
@ -1068,6 +1078,10 @@ class ServiceManager(Module.Module):
|
|||
self._updateServiceConf(s_conf, s_uuid,
|
||||
output=False)
|
||||
|
||||
global WS_LIST
|
||||
del WS_LIST['services'][s_uuid]
|
||||
print("(del)------> WS_LIST: " + str(WS_LIST))
|
||||
|
||||
LOG.info(" - " + message)
|
||||
|
||||
# Reactivate zombies monitoring
|
||||
|
|
|
@ -223,3 +223,14 @@ class WebServiceManager(Module.Module):
|
|||
w_msg = WM.WampSuccess(message)
|
||||
|
||||
return w_msg.serialize()
|
||||
|
||||
async def DisableWebService(self, req_id):
|
||||
|
||||
rpc_name = utils.getFuncName()
|
||||
LOG.info("RPC " + rpc_name + " CALLED [req_id: " + str(req_id) + "]")
|
||||
|
||||
message = self.board.proxy._proxyDisableWebService()
|
||||
|
||||
w_msg = WM.WampSuccess(message)
|
||||
|
||||
return w_msg.serialize()
|
||||
|
|
Loading…
Reference in New Issue