Skip to content

Instantly share code, notes, and snippets.

@V3ckt0r
Created June 25, 2016 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save V3ckt0r/d346c7f4b8a956111424d63a7756221f to your computer and use it in GitHub Desktop.
Save V3ckt0r/d346c7f4b8a956111424d63a7756221f to your computer and use it in GitHub Desktop.
Serviced service template
{
"ID": "",
"Name": "Python-Web-Server",
"Description": "Python Web Server",
"Services": [
{
"Name": "Python Web Server",
"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/local/bin/python /data/webserver.py -p 8000 -l /var/log/webserver.log",
"Description": "",
"Tags": [
"daemon"
],
"ImageID": "python:2.7.11",
"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, SocketServer\nimport datetime, time\nimport logging\nfrom BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer\n\nclass SimpleHTTPRequestHandler(BaseHTTPRequestHandler): \n\u0009def log_message(self, format, *args): \n\u0009\u0009open(logfile, \"a\").write(\"%s - - [%s] %s\\n\" % \n\u0009\u0009(self.address_string(), \n\u0009\u0009self.log_date_time_string(), \n\u0009\u0009format%args)) \n\u0009def do_GET(self):\n\u0009\u0009self.send_response(200)\n\u0009\u0009self.send_header('Content-type','text/html')\n\u0009\u0009self.end_headers()\n\u0009\u0009# Send the html message\n\u0009\u0009self.wfile.write(\"\u003chtml\u003e\u003ch1\u003eHello World !\u003c/h1\u003e\u003ch2\u003eFor more information on Zenoss Control Center, check out \u003ca href='http://controlcenter.io'\u003ehttp://controlcenter.io\u003c/a\u003e\u003c/h2\u003e \u003c/html\u003e \")\n\u0009\u0009return\ndef main(argv):\n\n# Init vars \n port = 0 \n global logfile\n logfile = '' \n logconfig ='' \n# Parse CLI Args \n try:\n opts, args = getopt.getopt(argv,\"h:p:l:\",[\"port=\",\"logfile=\"])\n except getopt.GetoptError:\n print 'webserver.py -p \u003cport\u003e -l \u003clog file\u003e'\n sys.exit(2)\n for opt, arg in opts:\n if opt == '-h':\n print 'webserver.py -p \u003cport\u003e -l \u003clog file\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 'no log file specified'\n sys.exit(2)\n\n# Set logging config\n logging.basicConfig(level=logging.DEBUG,\n format='%(asctime)s%(name)-12s%(levelname)-8s%(message)s',\n datefmt='%m-%d %H:%M:%S',\n filename=logfile,\n filemode='w') \n fh = logging.FileHandler(logfile) \n #fh.setFormatter = ('%(asctime)s %(levelname)s %(message)s')\n logger = logging.getLogger(' WWW') \n logger.addHandler(fh)\n \n try: \n\u0009httpd = HTTPServer(('',port), SimpleHTTPRequestHandler)\n# Log webserver startup\n \u0009logger.debug('HTTP server started')\n \u0009print '%s: HTTP server listening on TCP port: %d' % (datetime.datetime.now(),port) \n# Log webserver config \n \u0009logger.info('HTTP server listening on TCP port: %s',port)\n \u0009logger.info('HTTP server logfile: %s',logfile)\n\n# Run webserver as a long running process\n httpd.serve_forever()\n except getopt.GetoptError:\n \u0009print exc.msg\n \u0009sys.exit(2)\n\nif __name__ == \"__main__\":\n main(sys.argv[1:])\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": "apache",
"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": 1073741824,
"CPUCommitment": 2,
"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