A Service is the main element of a supercell application. It will instanciate the supercell.api.Environment and parse the configuration files as well as the command line. In the final step the tornado.web.Application is created and bound to a socket.
Main service implementation managing the tornado.web.Application and taking care of configuration.
Implement this method in order to manipulate the configuration paths, e.g..
Assemble the configration files and command line arguments in order to finalize the service’s configuration. All configuration values can be overwritten by the command line.
The default environment instance.
Create the tornado.web.Appliaction instance and return it.
Initialize the python logging system.
It is difficult to check whether the logging system is already initialized, so we are currently only checking if a SupercellLoggingHandler has already been added to the root logger. This should only be necessary when running unittests though.
Main method starting a supercell process.
This will first instantiate the tornado.web.Application and then bind it to the socket. There are two possibilities to bind to a socket: either by binding to a certain port and address as defined by the configuration (the port and address configuration settings) or by the socketfd command line parameter.
The latter is mainly used in combination with Circus (http://circus.readthedocs.org/). There you would bind the socket from circus and start the worker processes by binding to the file descriptor.
Parse the command line arguments to set different configuration values.
Parse the config files and return the config object, i.e. the tornado.options.options instance. For each entry in the Environment.config_file_paths() it will check for a general config.py and then for a file named as defined by Environment.config_name.
So if the config file paths are set to [‘/etc/myservice’, ‘./etc/’] the following files are parsed:
/etc/myservice/config.cfg /etc/myservice/user_hostname.cfg ./etc/config.cfg ./etc/user_hostname.cfg
By default we disable the tornado.log module, you can enable this though using by setting the logging config to some valid log level string.
Implement this method in order to add handlers and managed objects to the environment, before the app is started.
Gaceful shutdown of the server.
In this method we stop the tornado.httpserver in order to stop accepting new connections. During a period of max_grace_seconds current requests are allowed to finish. After this period the IOLoop is stopped.
Initialize the logging and return the logger.