Skip to content

Instantly share code, notes, and snippets.

@mmaloney
Created August 4, 2014 23:00
Show Gist options
  • Save mmaloney/ac3606788536f8062458 to your computer and use it in GitHub Desktop.
Save mmaloney/ac3606788536f8062458 to your computer and use it in GitHub Desktop.
Simple Python Web Server Template
{
"ID": "",
"Name": "Python Web Server",
"Description": "Simple Python web server",
"Services": [
{
"Name": "webserver",
"Command": "",
"Description": "Python web server",
"Tags": null,
"ImageID": "",
"Instances": {
"Min": 0,
"Max": 0
},
"ChangeOptions": null,
"Launch": "auto",
"HostPolicy": "",
"Hostname": "",
"Privileged": false,
"ConfigFiles": {},
"Context": null,
"Endpoints": null,
"Services": [
{
"Name": "python",
"Command": "/usr/bin/python /data/webserver.py -p 8000 -l /etc/python/log.conf",
"Description": "",
"Tags": [
"daemon"
],
"ImageID": "dockerfile/python:latest",
"Instances": {
"Min": 1,
"Max": 0
},
"ChangeOptions": null,
"Launch": "auto",
"HostPolicy": "",
"Hostname": "",
"Privileged": false,
"ConfigFiles": {
"/data/webserver.py": {
"Filename": "/data/webserver.py",
"Owner": "root",
"Permissions": "",
"Content": "import sys, getopt\nimport SimpleHTTPServer\nimport SocketServer\nimport time\nimport logging\nimport logging.config\n\ndef main(argv):\n \n# Init vars \n port = 0 \n logfile = '' \n \n try:\n opts, args = getopt.getopt(argv,\"hp:l:\",[\"port=\",\"logfile=\"])\n except getopt.GetoptError:\n print 'test.py -p \u003cport\u003e -o \u003clogfile\u003e'\n sys.exit(2)\n for opt, arg in opts:\n if opt == '-h':\n print 'webserver.py -p \u003cport\u003e -l \u003clogfile\u003e'\n sys.exit()\n elif opt in (\"-p\", \"--port\"):\n port=int(arg)\n elif opt in (\"-l\", \"--logfile\"):\n logfile = arg\n if port == 0:\n print 'invalid port specified'\n sys.exit(2)\n if logfile == '':\n print 'invalid logfile specified'\n sys.exit(2)\n\n# Set logging config\n\n logging.config.fileConfig(logfile)\n\n Handler = SimpleHTTPServer.SimpleHTTPRequestHandler\n\n\n try: \n \u0009httpd = SocketServer.TCPServer((\"\", port), Handler)\n\n# Log webserver startup\n \u0009logging.info('HTTP server started')\n \u0009print \"HTTP server listening on TCP port\", port \n\n# Log webserver config \n \u0009logging.info('HTTP server listening on TCP port: %s',port)\n \u0009logging.info('HTTP server logfile: %s',logfile)\n\n# Run webserver as a long running process\n \u0009httpd.serve_forever()\n\n except getopt.GetoptError:\n \u0009print exc.msg\n \u0009sys.exit(2)\n\nif __name__ == \"__main__\":\n main(sys.argv[1:])\n"
},
"/etc/python/log.conf": {
"Filename": "/etc/python/log.conf",
"Owner": "",
"Permissions": "",
"Content": "[loggers]\nkeys=root,simpleExample\n\n[logfile]\nfilename=/var/log/webserver.log\n\n[handlers]\nkeys=consoleHandler\n\n[formatters]\nkeys=simpleFormatter\n\n[logger_root]\nlevel=DEBUG\nhandlers=consoleHandler\n\n[logger_simpleExample]\nlevel=DEBUG\nhandlers=consoleHandler\nqualname=simpleExample\npropagate=0\n\n[handler_consoleHandler]\nclass=StreamHandler\nlevel=DEBUG\nformatter=simpleFormatter\nargs=(sys.stdout,)\nfilename='/var/log/webserver.log',format='%(asctime)s %(levelname)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p',level=logging.DEBUG\n[formatter_simpleFormatter]\nformat=%(asctime)s %(levelname)s %(message)s\ndatefmt=%m/%d/%Y %I:%M:%S %p\n"
}
},
"Context": null,
"Endpoints": [
{
"Name": "http",
"Purpose": "export",
"Protocol": "tcp",
"PortNumber": 8000,
"PortTemplate": "",
"VirtualAddress": "",
"Application": "http",
"ApplicationTemplate": "",
"AddressConfig": {
"Port": 8000,
"Protocol": "tcp"
},
"VHosts": [
"web"
]
}
],
"Services": [],
"Tasks": null,
"LogFilters": null,
"Volumes": null,
"LogConfigs": [
{
"Path": "/var/log/webserver.log",
"Type": "webserver",
"Filters": null,
"LogTags": null
}
],
"Snapshot": {
"Pause": "",
"Resume": ""
},
"RAMCommitment": 136870912,
"CPUCommitment": 0,
"Runs": null,
"Actions": {
"status": "ps -ef | grep [p]ython"
},
"HealthChecks": {
"running": {
"Script": "echo $?",
"Interval": 20
}
},
"Prereqs": null,
"MonitoringProfile": {
"MetricConfigs": null,
"GraphConfigs": null,
"ThresholdConfigs": null
},
"MemoryLimit": 0,
"CPUShares": 0,
"PIDFile": ""
}
],
"Tasks": null,
"LogFilters": null,
"Volumes": null,
"LogConfigs": null,
"Snapshot": {
"Pause": "",
"Resume": ""
},
"RAMCommitment": 4073741824,
"CPUCommitment": 4,
"Runs": null,
"Actions": null,
"HealthChecks": null,
"Prereqs": null,
"MonitoringProfile": {
"MetricConfigs": null,
"GraphConfigs": null,
"ThresholdConfigs": null
},
"MemoryLimit": 0,
"CPUShares": 0,
"PIDFile": ""
}
],
"ConfigFiles": null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment