66 lines
1.3 KiB
Python
Executable File
66 lines
1.3 KiB
Python
Executable File
#!/usr/bin/python
|
|
|
|
import SocketServer
|
|
import socket
|
|
import os
|
|
import ConfigParser
|
|
import getopt
|
|
import sys
|
|
|
|
from Logging import *
|
|
from SendmailSocketMapHandler import SendmailDispatcher
|
|
|
|
|
|
def usage():
|
|
print "Usage"
|
|
|
|
|
|
try:
|
|
opts, args = getopt.getopt(sys.argv[1:], "hC:F", ["help", "ConfigFile=", "ForeGround"])
|
|
except getopt.GetoptError:
|
|
usage()
|
|
sys.exit(2)
|
|
|
|
configFile = '/etc/smmapd.ini'
|
|
foreGround = None
|
|
for o, a in opts:
|
|
if o in ("-h", "--help"):
|
|
usage()
|
|
sys.exit()
|
|
if o in ("-C", "--ConfigFile"):
|
|
configFile = a
|
|
if o in ("-F", "--ForeGround"):
|
|
foreGround = 1
|
|
|
|
|
|
|
|
config = ConfigParser.ConfigParser()
|
|
config.read(configFile)
|
|
|
|
openlog(config)
|
|
|
|
if foreGround:
|
|
pid = 0
|
|
else:
|
|
pid = os.fork()
|
|
|
|
if pid:
|
|
pidFile = file(config.get('Daemon', 'PidFile'), mode='w')
|
|
pidFile.write("%i\n" % pid)
|
|
pidFile.close()
|
|
print "daemon started with pid ", pid
|
|
else:
|
|
log("daemon started")
|
|
|
|
SendmailDispatcher.registerAll(config)
|
|
|
|
try:
|
|
address = config.get('Daemon', 'Address')
|
|
port = int(config.get('Daemon', 'Port'))
|
|
srv = SocketServer.ThreadingTCPServer((address, port), SendmailDispatcher)
|
|
srv.serve_forever()
|
|
except socket.error, arg:
|
|
log("got a socket error: %s" % str(arg))
|
|
log("daemon died")
|
|
|