]> jfr.im git - irc/quakenet/qwebirc.git/blame_incremental - run.py
correct spelling of licence
[irc/quakenet/qwebirc.git] / run.py
... / ...
CommitLineData
1#!/usr/bin/env python
2# this entire thing is a hack and badly needs reimplementing
3import bin.compile
4bin.compile.vcheck()
5
6DEFAULT_PORT = 9090
7
8from optparse import OptionParser
9import sys, os, config
10
11def run_twistd(args1=None, args2=None):
12 from twisted.scripts.twistd import run
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)
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)
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)
35parser.add_option("-i", "--ip", help="IP address to listen on.", dest="ip", default="0.0.0.0")
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")
38parser.add_option("-C", "--certificate", help="Path to SSL certificate.", dest="sslcertificate")
39parser.add_option("-k", "--key", help="Path to SSL key.", dest="sslkey")
40parser.add_option("-H", "--certificate-chain", help="Path to SSL certificate chain file.", dest="sslchain")
41parser.add_option("-P", "--pidfile", help="Path to store PID file", dest="pidfile")
42parser.add_option("-s", "--syslog", help="Log to syslog", action="store_true", dest="syslog", default=False)
43parser.add_option("--profile", help="Run in profile mode, dumping results to this file", dest="profile")
44parser.add_option("--profiler", help="Name of profiler to use", dest="profiler")
45parser.add_option("--syslog-prefix", help="Syslog prefix", dest="syslog_prefix", default="qwebirc")
46
47sargs = sys.argv[1:]
48if "ARGS" in dir(config):
49 import shlex
50 sargs = shlex.split(config.ARGS) + sargs
51
52(options, args) = parser.parse_args(args=sargs)
53
54args1, args2 = [], []
55
56if not options.daemonise:
57 args1.append("-n")
58if options.debug:
59 args1.append("-b")
60
61if options.reactor != DEFAULT_REACTOR:
62 rn = options.reactor + "reactor"
63 getattr(__import__("twisted.internet", fromlist=[rn]), rn).install()
64if options.logfile:
65 args1+=["--logfile", options.logfile]
66if options.pidfile:
67 args1+=["--pidfile", options.pidfile]
68if options.syslog:
69 args1+=["--syslog"]
70if options.profile:
71 args1+=["--profile", options.profile]
72if options.profiler:
73 args1+=["--profiler", options.profiler]
74
75if options.syslog and options.syslog_prefix:
76 import syslog
77 syslog.openlog(options.syslog_prefix)
78
79if not options.tracebacks:
80 args2.append("-n")
81if options.clogfile:
82 args2+=["--logfile", options.clogfile]
83
84if options.sslcertificate and options.sslkey:
85 args2+=["--certificate", options.sslcertificate, "--privkey", options.sslkey, "--https", options.port]
86 if options.sslchain:
87 args2+=["--certificate-chain", options.sslchain]
88else:
89 args2+=["--port", options.port]
90
91args2+=["--ip", options.ip]
92
93run_twistd(args1, args2)