Commit 00197599 authored by Srikanth Raju's avatar Srikanth Raju Committed by Leigh B Stoller

Make the meta server a daemon

parent 920c5185
#!/usr/local/bin/python
from BaseHTTPServer import BaseHTTPRequestHandler from BaseHTTPServer import BaseHTTPRequestHandler
import urlparse import urlparse
import traceback import traceback
import os import os
import sys import sys
import mysql.connector import mysql.connector
import daemon
from lockfile import pidlockfile
class Ec2MetaHandler(BaseHTTPRequestHandler): class Ec2MetaHandler(BaseHTTPRequestHandler):
...@@ -14,8 +17,6 @@ class Ec2MetaHandler(BaseHTTPRequestHandler): ...@@ -14,8 +17,6 @@ class Ec2MetaHandler(BaseHTTPRequestHandler):
BaseHTTPRequestHandler.__init__(self,req,ca,huh) BaseHTTPRequestHandler.__init__(self,req,ca,huh)
def do_GET(self): def do_GET(self):
parsed_path = urlparse.urlparse(self.path) parsed_path = urlparse.urlparse(self.path)
...@@ -214,21 +215,11 @@ class Ec2MetaHandler(BaseHTTPRequestHandler): ...@@ -214,21 +215,11 @@ class Ec2MetaHandler(BaseHTTPRequestHandler):
if __name__ == '__main__': if __name__ == '__main__':
from BaseHTTPServer import HTTPServer from BaseHTTPServer import HTTPServer
import socket import socket
server = HTTPServer((socket.gethostbyname(socket.gethostname()), 8787), Ec2MetaHandler) metad = daemon.DaemonContext()
pid = str(os.getpid()) metad.pidfile = pidlockfile.PIDLockFile('/var/run/tmcd-meta.pid')
pidfile = "/var/run/tmcd-meta.pid" with metad:
server = HTTPServer((socket.gethostbyname(socket.gethostname()), 8787),
if os.path.isfile(pidfile): Ec2MetaHandler)
print "%s already exists, exiting" % pidfile
sys.exit()
else:
file(pidfile, 'w').write(pid)
try:
print 'Starting server, use <Ctrl-C> to stop'
server.serve_forever() server.serve_forever()
finally:
os.unlink(pidfile)
...@@ -110,7 +110,8 @@ version.c: tmcd.c ...@@ -110,7 +110,8 @@ version.c: tmcd.c
install: all install: all
install: $(INSTALL_SBINDIR)/tmcd \ install: $(INSTALL_SBINDIR)/tmcd \
$(INSTALL_SBINDIR)/tmcd.restart $(INSTALL_SBINDIR)/tmcd.restart \
$(INSTALL_SBINDIR)/Ec2MetaServer.py
control-install: control-install:
boss-install: install boss-install: install
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment