1
0
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:
zbeacon
2020-05-11 17:24:12 +03:00
parent 7f0c085e5b
commit 59923c2fc9
3 changed files with 15 additions and 12 deletions

View File

@@ -49,6 +49,7 @@ main_handler = logging.handlers.MemoryHandler(-1)
class TBGatewayService:
def __init__(self, config_file=None):
self.stopped = False
self.__lock = RLock()
if config_file is None:
config_file = path.dirname(path.dirname(path.abspath(__file__))) + '/config/tb_gateway.yaml'.replace('/', path.sep)
@@ -133,7 +134,7 @@ class TBGatewayService:
try:
gateway_statistic_send = 0
while True:
while not self.stopped:
cur_time = time()*1000
if 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
# self.__check_shared_attributes()
except KeyboardInterrupt:
log.info("Stopping...")
self.__close_connectors()
log.info("The gateway has been stopped.")
self.tb_client.stop()
self.__stop_gateway()
except Exception as e:
log.exception(e)
self.__close_connectors()
@@ -191,7 +189,11 @@ class TBGatewayService:
log.exception(e)
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):
try:

View File

@@ -26,16 +26,15 @@ from thingsboard_gateway.tb_utility.tb_utility import TBUtility
log = getLogger("service")
UPDATE_SERVICE_BASE_URL = "https://updates.thingsboard.io"
# UPDATE_SERVICE_BASE_URL = "http://0.0.0.0:8090"
# UPDATE_SERVICE_BASE_URL = "https://updates.thingsboard.io"
UPDATE_SERVICE_BASE_URL = "http://0.0.0.0:8090"
class TBUpdater(Thread):
def __init__(self, gateway, auto_updates_enabled):
super().__init__()
self.__gateway = gateway
# self.__version = get_distribution('thingsboard_gateway').version
self.__version = "1.2.1" #For test
self.__version = get_distribution('thingsboard_gateway').version
self.__instance_id = str(uuid1())
self.__platform = "deb"
self.__os_version = platform()
@@ -45,7 +44,7 @@ class TBUpdater(Thread):
self.start()
def run(self):
while True:
while not self.__gateway.stopped:
self.check_for_new_version()
sleep(self.__check_period)
@@ -63,6 +62,8 @@ class TBUpdater(Thread):
new_version = content["message"].replace("New version ", "").replace(" is available!", "")
log.info(content["message"])
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:
log.exception(e)