Quantcast
Channel: Planet Python
Viewing all articles
Browse latest Browse all 22462

Zato Blog: Reloading user config in Zato 2.0 without server restarts

$
0
0

Since its inception, Zato has always offered hot-deployment, which means that it is possible to update code of one's SOA/API services without restarting servers - simply upload a new version of a given Python module and it is automatically distributed to all servers forming a cluster.

The next major version will extend it to user configuration as well - so you will be able to edit any .ini config file on any server and all changes will be propagated to other servers each time that file is saved, just like with services today.

In Zato 2.0 a little piece of code such as the one below can be used to achieve the same effect.

Essentially - after updating a config file, for instance user.conf, you need to invoke the 'util.config.reload' service, can be either directly from web-admin, command line or over HTTP, AMQP, ZeroMQ or any other channel.

This will publish an internal message to all servers prompting them to re-read all user-provided configuration files.

In this manner, there is even less need to restart servers - after all, why restart the whole server if only a file or two changed?

# -*- coding: utf-8 -*-from__future__importabsolute_import,division,print_function,unicode_literals# Zatofromzato.common.broker_messageimportSERVICEfromzato.common.utilimportget_config,new_cidfromzato.server.serviceimportServiceclass_Reload(Service):name='util.config._reload'defhandle(self):server_conf=get_config(self.server.repo_location,'server.conf')self.server.user_config.clear()self.server.user_config.update(server_conf.user_config_items)self.logger.info('User config reloaded')classReload(Service):name='util.config.reload'defhandle(self):msg={}msg['action']=SERVICE.PUBLISH.valuemsg['service']=_Reload.namemsg['payload']=''msg['cid']=new_cid()self.broker_client.publish(msg)

Viewing all articles
Browse latest Browse all 22462

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>