Browse Source

add ApiServer to batcave

Helge Jung 10 years ago
parent
commit
28fc0d441d
2 changed files with 12 additions and 0 deletions
  1. 9 0
      batcave.py
  2. 3 0
      ffstatus/server.py

+ 9 - 0
batcave.py

@@ -6,6 +6,7 @@ import daemon
 import logging
 import sys
 import time
+import threading
 
 from ffstatus import *
 
@@ -22,6 +23,8 @@ parser.add_argument('-G', '--graphite-host', help='Graphite host')
 parser.add_argument('--graphite-port', type=int, default=2003, help='Graphite port')
 parser.add_argument('--dashing-url', help='Dashing URL')
 parser.add_argument('--dashing-token', help='Dashing\'s secret update token')
+parser.add_argument('--api-bind-host', default='::', help='API-Server Hostname')
+parser.add_argument('--api-bind-port', type=int, default=8888, help='API-Server Port')
 args = parser.parse_args()
 
 if args.interval < 5:
@@ -71,6 +74,12 @@ for i in [ ('AlfredParser', a), ('BatmanParser', b) ]:
 		print('FAILED SANITY CHECK: ' + str(err))
 		sys.exit(1)
 
+server = ApiServer((args.api_bind_host, args.api_bind_port), storage)
+server_thread = threading.Thread(target=server.serve_forever)
+server_thread.daemon = True # exit thread when main thread terminates
+server_thread.start()
+logger.info('Started server: ' + str(server))
+
 if shall_daemonize:
 	daemon_context = daemon.DaemonContext(
 		files_preserve = [ fh.stream ],

+ 3 - 0
ffstatus/server.py

@@ -114,6 +114,9 @@ class ApiServer(ThreadingMixIn, HTTPServer):
 		HTTPServer.__init__(self, endpoint, BatcaveHttpRequestHandler)
 		self.storage = storage
 
+	def __str__(self):
+		return 'ApiServer on {0}'.format(self.server_address)
+
 if __name__ == '__main__':
 	dummystorage = Storage()
 	server = ApiServer(('0.0.0.0', 8888), dummystorage)