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.
supercell.service.
Service
¶Main service implementation managing the
tornado.web.Application
and taking care of configuration.
bootstrap
()¶Implement this method in order to manipulate the configuration paths, e.g..
config
¶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.
environment
¶The default environment instance.
get_app
()¶Create the tornado.web.Appliaction
instance and return it.
In this method the Service.bootstrap()
is called, then
Service.run()
will initialize the app.
initialize_logging
()¶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
(with_signals=True)¶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_command_line
()¶Parse the command line arguments to set different configuration values.
parse_config_files
()¶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
Note
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.
run
()¶Implement this method in order to add handlers and managed objects to the environment, before the app is started.
shutdown
()¶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.
slog
¶Initialize the logging and return the logger.