]> jfr.im git - irc/quakenet/qwebirc.git/blame - run.py
Switch to using SRV records.
[irc/quakenet/qwebirc.git] / run.py
CommitLineData
8b8ebb78 1#!/usr/bin/env python
1d924d97 2# this entire thing is a hack and badly needs reimplementing
a409b906
CP
3import bin.compile
4bin.compile.vcheck()
5
8b8ebb78
CP
6DEFAULT_PORT = 9090
7
8from twisted.scripts.twistd import run
9from optparse import OptionParser
42fdc4c6 10import sys, os, config
8b8ebb78
CP
11
12def run_twistd(args1=None, args2=None):
13 args = [sys.argv[0]]
14 if args1 is not None:
15 args.extend(args1)
16 args.append("qwebirc")
17 if args2 is not None:
18 args.extend(args2)
19 sys.argv = args
20 run()
21
22def help_reactors(*args):
23 run_twistd(["--help-reactors"])
24 sys.exit(1)
25
26DEFAULT_REACTOR = "select" if os.name == "nt" else "poll"
27
28parser = OptionParser()
29parser.add_option("-n", "--no-daemon", help="Don't run in the background.", action="store_false", dest="daemonise", default=True)
30parser.add_option("--help-reactors", help="Display a list of reactor names.", action="callback", callback=help_reactors)
31parser.add_option("-b", "--debug", help="Run in the Python Debugger.", action="store_true", dest="debug", default=False)
0f3c92dc 32parser.add_option("-t", "--tracebacks", help="Display tracebacks in error pages (this reveals a LOT of information, do NOT use in production!)", action="store_true", dest="tracebacks", default=False)
8b8ebb78
CP
33parser.add_option("-r", "--reactor", help="Which reactor to use (see --help-reactors for a list).", dest="reactor", default=DEFAULT_REACTOR)
34parser.add_option("-p", "--port", help="Port to start the server on.", type="int", dest="port", default=DEFAULT_PORT)
ef74f2c1 35parser.add_option("-i", "--ip", help="IP address to listen on.", dest="ip", default="0.0.0.0")
8b8ebb78
CP
36parser.add_option("-l", "--logfile", help="Path to twisted log file.", dest="logfile")
37parser.add_option("-c", "--clf", help="Path to web CLF (Combined Log Format) log file.", dest="clogfile")
64429ed7
CP
38parser.add_option("-C", "--certificate", help="Path to SSL certificate.", dest="sslcertificate")
39parser.add_option("-k", "--key", help="Path to SSL key.", dest="sslkey")
9e93b6fe 40parser.add_option("-H", "--certificate-chain", help="Path to SSL certificate chain file.", dest="sslchain")
4cfa1a92 41parser.add_option("-P", "--pidfile", help="Path to store PID file", dest="pidfile")
39cf79cc
CP
42parser.add_option("-s", "--syslog", help="Log to syslog", action="store_true", dest="syslog", default=False)
43parser.add_option("--syslog-prefix", help="Syslog prefix", dest="syslog_prefix", default="qwebirc")
42fdc4c6
CP
44
45sargs = sys.argv[1:]
46if "ARGS" in dir(config):
47 import shlex
48 sargs = shlex.split(config.ARGS) + sargs
49
50(options, args) = parser.parse_args(args=sargs)
8b8ebb78
CP
51
52args1, args2 = [], []
53
54if not options.daemonise:
55 args1.append("-n")
56if options.debug:
57 args1.append("-b")
4bc06f30
CP
58
59if options.reactor != DEFAULT_REACTOR:
60 args1+=["--reactor", options.reactor]
8b8ebb78 61if options.logfile:
4cfa1a92
CP
62 args1+=["--logfile", options.logfile]
63if options.pidfile:
64 args1+=["--pidfile", options.pidfile]
39cf79cc
CP
65if options.syslog:
66 args1+=["--syslog"]
94ba3643 67if options.syslog and options.syslog_prefix:
39cf79cc
CP
68 import syslog
69 syslog.openlog(options.syslog_prefix)
8b8ebb78 70
0f3c92dc
CP
71if not options.tracebacks:
72 args2.append("-n")
8b8ebb78
CP
73if options.clogfile:
74 args2+=["--logfile", options.clogfile]
0f3c92dc 75
64429ed7
CP
76if options.sslcertificate and options.sslkey:
77 args2+=["--certificate", options.sslcertificate, "--privkey", options.sslkey, "--https", options.port]
9e93b6fe
CP
78 if options.sslchain:
79 args2+=["--certificate-chain", options.sslchain]
64429ed7
CP
80else:
81 args2+=["--port", options.port]
82
ef74f2c1 83args2+=["--ip", options.ip]
84
8b8ebb78 85run_twistd(args1, args2)