appname/management/commands/smtpd.py
class Command(BaseCommand):
def handle(self, *args, **options):
daemon_kwargs = {}
daemon_kwargs['out_log'] = options.get('outlog', 'smtp_out.log')
daemon_kwargs['err_log'] = options.get('errlog', 'smtp_err.log')
from django.utils.daemonize import become_daemon
become_daemon(**daemon_kwargs)
foo = MySMTPServer((settings.EMAIL_HOST, settings.EMAIL_PORT),
(settings.PARENT_SMTP_HOST, settings.PARENT_SMTP_PORT))
try:
asyncore.loop()
except KeyboardInterrupt:
pass
class MySMTPServer(smtpd.SMTPServer):
def process_message(self, peer, mailfrom, rcpttos, data):
""" なんか素敵なことをする """
たった1行でDaemon化できるのが素敵。
0 件のコメント:
コメントを投稿