1
# -*- test-case-name: twisted.test.test_twistd -*-
2
# Copyright (c) 2001-2008 Twisted Matrix Laboratories.
3
# See LICENSE for details.
5
from twisted.python import log
6
from twisted.application import app, service, internet
7
from twisted import copyright
12
class ServerOptions(app.ServerOptions):
13
synopsis = "Usage: twistd [options]"
15
optFlags = [['nodaemon','n', "(for backwards compatability)."],
18
def opt_version(self):
19
"""Print version information and exit.
21
print 'twistd (the Twisted Windows runner) %s' % copyright.version
22
print copyright.copyright
27
class WindowsApplicationRunner(app.ApplicationRunner):
29
An ApplicationRunner which avoids unix-specific things. No
30
forking, no PID files, no privileges.
33
def preApplication(self):
35
Do pre-application-creation setup.
37
self.oldstdout = sys.stdout
38
self.oldstderr = sys.stderr
39
os.chdir(self.config['rundir'])
42
def postApplication(self):
44
Start the application and run the reactor.
46
service.IService(self.application).privilegedStartService()
47
app.startApplication(self.application, not self.config['no_save'])
48
app.startApplication(internet.TimerService(0.1, lambda:None), 0)
49
self.startReactor(None, self.oldstdout, self.oldstderr)
50
log.msg("Server Shut Down.")