I'm using txnet in an application to monitor if some servers are up, it has a web interface so the reactor along with listenICMP for ping requests (is the reactor provided in txnet) also listenTCP for the web server. My question is about how to daemonize with twistd. Twisted.internet.application provide according to the api:
TCPServer, TCPClient, UNIXServer, UNIXClient, SSLServer, SSLClient, UDPServer, UDPClient, UNIXDatagramServer, UNIXDatagramClient, MulticastServer
I'm guessing i have to implement my own service, but i cand find a nice example on doing this, best explanation online probably krondo tutorial daemonology but it has no references on change the reactor. Summaring: What is the best choice in order to daemonize something like this?:
import json
from txnet.reactor import reactor
from twisted.web import server, resource
from twisted.internet.protocol import DatagramProtocol
result = {}
class PingProtocol(DatagramProtocol):
ICMP_ECHOREPLY = 0
def datagramReceived(self, datagram, address):
ip, port = address
result[ip] = True
class WebServer(resource.Resource):
def __init__(self):
resource.Resource.__init__(self)
self.putChild('', self)
def render_GET(self, request):
str = json.dumps(result)
result.clear()
return str
wserver = WebServer()
reactor.listenTCP(8081, server.Site(wserver))
reactor.listenICMP(0, PingProtocol())
reactor.run()
I know that listenUDP probably do the work here, but this is a simplified version, i really need to listenICMP.