]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/env python | |
2 | # this entire thing is a hack and badly needs reimplementing | |
3 | import bin.compile | |
4 | bin.compile.vcheck() | |
5 | ||
6 | DEFAULT_PORT = 9090 | |
7 | ||
8 | from twisted.scripts.twistd import run | |
9 | from optparse import OptionParser | |
10 | import sys, os, config | |
11 | ||
12 | def 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 | ||
22 | def help_reactors(*args): | |
23 | run_twistd(["--help-reactors"]) | |
24 | sys.exit(1) | |
25 | ||
26 | DEFAULT_REACTOR = "select" if os.name == "nt" else "poll" | |
27 | ||
28 | parser = OptionParser() | |
29 | parser.add_option("-n", "--no-daemon", help="Don't run in the background.", action="store_false", dest="daemonise", default=True) | |
30 | parser.add_option("--help-reactors", help="Display a list of reactor names.", action="callback", callback=help_reactors) | |
31 | parser.add_option("-b", "--debug", help="Run in the Python Debugger.", action="store_true", dest="debug", default=False) | |
32 | parser.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) | |
33 | parser.add_option("-r", "--reactor", help="Which reactor to use (see --help-reactors for a list).", dest="reactor", default=DEFAULT_REACTOR) | |
34 | parser.add_option("-p", "--port", help="Port to start the server on.", type="int", dest="port", default=DEFAULT_PORT) | |
35 | parser.add_option("-i", "--ip", help="IP address to listen on.", dest="ip", default="0.0.0.0") | |
36 | parser.add_option("-l", "--logfile", help="Path to twisted log file.", dest="logfile") | |
37 | parser.add_option("-c", "--clf", help="Path to web CLF (Combined Log Format) log file.", dest="clogfile") | |
38 | parser.add_option("-C", "--certificate", help="Path to SSL certificate.", dest="sslcertificate") | |
39 | parser.add_option("-k", "--key", help="Path to SSL key.", dest="sslkey") | |
40 | parser.add_option("-P", "--pidfile", help="Path to store PID file", dest="pidfile") | |
41 | parser.add_option("-s", "--syslog", help="Log to syslog", action="store_true", dest="syslog", default=False) | |
42 | parser.add_option("--syslog-prefix", help="Syslog prefix", dest="syslog_prefix", default="qwebirc") | |
43 | ||
44 | sargs = sys.argv[1:] | |
45 | if "ARGS" in dir(config): | |
46 | import shlex | |
47 | sargs = shlex.split(config.ARGS) + sargs | |
48 | ||
49 | (options, args) = parser.parse_args(args=sargs) | |
50 | ||
51 | args1, args2 = [], [] | |
52 | ||
53 | if not options.daemonise: | |
54 | args1.append("-n") | |
55 | if options.debug: | |
56 | args1.append("-b") | |
57 | ||
58 | if options.reactor != DEFAULT_REACTOR: | |
59 | args1+=["--reactor", options.reactor] | |
60 | if options.logfile: | |
61 | args1+=["--logfile", options.logfile] | |
62 | if options.pidfile: | |
63 | args1+=["--pidfile", options.pidfile] | |
64 | if options.syslog: | |
65 | args1+=["--syslog"] | |
66 | if options.syslog and options.syslog_prefix: | |
67 | import syslog | |
68 | syslog.openlog(options.syslog_prefix) | |
69 | ||
70 | if not options.tracebacks: | |
71 | args2.append("-n") | |
72 | if options.clogfile: | |
73 | args2+=["--logfile", options.clogfile] | |
74 | ||
75 | if options.sslcertificate and options.sslkey: | |
76 | args2+=["--certificate", options.sslcertificate, "--privkey", options.sslkey, "--https", options.port] | |
77 | else: | |
78 | args2+=["--port", options.port] | |
79 | ||
80 | args2+=["--ip", options.ip] | |
81 | ||
82 | run_twistd(args1, args2) |