mirror of
https://github.com/thingsboard/thingsboard-gateway
synced 2025-10-26 22:31:42 +08:00
Auto update feature
This commit is contained in:
@@ -49,6 +49,7 @@ main_handler = logging.handlers.MemoryHandler(-1)
|
|||||||
|
|
||||||
class TBGatewayService:
|
class TBGatewayService:
|
||||||
def __init__(self, config_file=None):
|
def __init__(self, config_file=None):
|
||||||
|
self.stopped = False
|
||||||
self.__lock = RLock()
|
self.__lock = RLock()
|
||||||
if config_file is None:
|
if config_file is None:
|
||||||
config_file = path.dirname(path.dirname(path.abspath(__file__))) + '/config/tb_gateway.yaml'.replace('/', path.sep)
|
config_file = path.dirname(path.dirname(path.abspath(__file__))) + '/config/tb_gateway.yaml'.replace('/', path.sep)
|
||||||
@@ -133,7 +134,7 @@ class TBGatewayService:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
gateway_statistic_send = 0
|
gateway_statistic_send = 0
|
||||||
while True:
|
while not self.stopped:
|
||||||
cur_time = time()*1000
|
cur_time = time()*1000
|
||||||
if self.__sheduled_rpc_calls:
|
if self.__sheduled_rpc_calls:
|
||||||
for rpc_call_index in range(len(self.__sheduled_rpc_calls)):
|
for rpc_call_index in range(len(self.__sheduled_rpc_calls)):
|
||||||
@@ -172,10 +173,7 @@ class TBGatewayService:
|
|||||||
gateway_statistic_send = time()*1000
|
gateway_statistic_send = time()*1000
|
||||||
# self.__check_shared_attributes()
|
# self.__check_shared_attributes()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
log.info("Stopping...")
|
self.__stop_gateway()
|
||||||
self.__close_connectors()
|
|
||||||
log.info("The gateway has been stopped.")
|
|
||||||
self.tb_client.stop()
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.exception(e)
|
log.exception(e)
|
||||||
self.__close_connectors()
|
self.__close_connectors()
|
||||||
@@ -191,7 +189,11 @@ class TBGatewayService:
|
|||||||
log.exception(e)
|
log.exception(e)
|
||||||
|
|
||||||
def __stop_gateway(self):
|
def __stop_gateway(self):
|
||||||
pass
|
self.stopped = True
|
||||||
|
log.info("Stopping...")
|
||||||
|
self.__close_connectors()
|
||||||
|
log.info("The gateway has been stopped.")
|
||||||
|
self.tb_client.stop()
|
||||||
|
|
||||||
def _attributes_parse(self, content, *args):
|
def _attributes_parse(self, content, *args):
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -26,16 +26,15 @@ from thingsboard_gateway.tb_utility.tb_utility import TBUtility
|
|||||||
|
|
||||||
log = getLogger("service")
|
log = getLogger("service")
|
||||||
|
|
||||||
UPDATE_SERVICE_BASE_URL = "https://updates.thingsboard.io"
|
# UPDATE_SERVICE_BASE_URL = "https://updates.thingsboard.io"
|
||||||
# UPDATE_SERVICE_BASE_URL = "http://0.0.0.0:8090"
|
UPDATE_SERVICE_BASE_URL = "http://0.0.0.0:8090"
|
||||||
|
|
||||||
|
|
||||||
class TBUpdater(Thread):
|
class TBUpdater(Thread):
|
||||||
def __init__(self, gateway, auto_updates_enabled):
|
def __init__(self, gateway, auto_updates_enabled):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.__gateway = gateway
|
self.__gateway = gateway
|
||||||
# self.__version = get_distribution('thingsboard_gateway').version
|
self.__version = get_distribution('thingsboard_gateway').version
|
||||||
self.__version = "1.2.1" #For test
|
|
||||||
self.__instance_id = str(uuid1())
|
self.__instance_id = str(uuid1())
|
||||||
self.__platform = "deb"
|
self.__platform = "deb"
|
||||||
self.__os_version = platform()
|
self.__os_version = platform()
|
||||||
@@ -45,7 +44,7 @@ class TBUpdater(Thread):
|
|||||||
self.start()
|
self.start()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
while True:
|
while not self.__gateway.stopped:
|
||||||
self.check_for_new_version()
|
self.check_for_new_version()
|
||||||
sleep(self.__check_period)
|
sleep(self.__check_period)
|
||||||
|
|
||||||
@@ -63,6 +62,8 @@ class TBUpdater(Thread):
|
|||||||
new_version = content["message"].replace("New version ", "").replace(" is available!", "")
|
new_version = content["message"].replace("New version ", "").replace(" is available!", "")
|
||||||
log.info(content["message"])
|
log.info(content["message"])
|
||||||
TBUtility.install_package("thingsboard-gateway", new_version)
|
TBUtility.install_package("thingsboard-gateway", new_version)
|
||||||
|
except ConnectionRefusedError:
|
||||||
|
log.warning("Cannot connect to the update service. PLease check your internet connection.")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.exception(e)
|
log.exception(e)
|
||||||
|
|
||||||
|
|||||||
@@ -157,4 +157,4 @@ class TBUtility:
|
|||||||
if version.lower() == "upgrade":
|
if version.lower() == "upgrade":
|
||||||
check_call([executable, "-m", "pip", "install", package, "--upgrade", "--user"])
|
check_call([executable, "-m", "pip", "install", package, "--upgrade", "--user"])
|
||||||
else:
|
else:
|
||||||
check_call([executable, "-m", "pip", "install", package + version, "--user"])
|
check_call([executable, "-m", "pip", "install", package + "==" + version, "--user"])
|
||||||
|
|||||||
Reference in New Issue
Block a user