Skip to navigation
Flask api webserver with multiple ports from supervisor
17.08.17
1. server.py: #!/usr/bin/env python from flask import Flask, jsonify import controller,time import optparse app = Flask(__name__) tasks = { 'foo':{'url':'http://foo.com/'} } @app.route('/controller/api/v1.0/tasks/
', methods=['GET']) def get_task(task_name=False): if(task_name in tasks): return jsonify( { 'task': task_name, 'executed': time.strftime("%d.%m.%Y %H:%M:%S", time.localtime()), 'storage': tasks[task_name]['url'] }) else: return jsonify({'task': '{} not registered'.format(task_name)}) if __name__ == '__main__': default_port = 5000 parser = optparse.OptionParser() parser.add_option("-P", "--port", help="Port for the Flask app " + "[default %s]" % default_port, default=default_port ) options, _ = parser.parse_args() app.run(debug=True,host='0.0.0.0',port=int(options.port)) 2. /etc/supervisor/conf.d/server.conf: [program:server] process_name=controller_server%(process_num)s directory=/var/customers/webs/controller/ command=/var/customers/webs/controller/env/bin/python /var/customers/webs/controller/server.py --port=%(process_num)s numprocs=10 numprocs_start=5000 autostart=true startretries=100 startsecs=0
http://flask.pocoo.org/snippets/133/
Reply
Anonymous
Information Epoch 1732664262
Design programs to be connected to other programs.
Home
Notebook
Contact us