~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/canonical/not-used/hctapi/runlaunchpad-trebuchet.py

merge from rf

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2005 Canonical Ltd.  All rights reserved.
 
2
 
 
3
# NOTE: This code was taken out of runlaunchpad.py. It was used to start the
 
4
# trebuchet daemon, however this daemon has been superseded by the generic
 
5
# Launchpad xmlrpc server. -- David Allouche 2006-09-25
 
6
 
 
7
import atexit
 
8
import os
 
9
import signal
 
10
import subprocess
 
11
import sys
 
12
 
 
13
 
 
14
def start_trebuchet():
 
15
    # Imported here as path is not set fully on module load
 
16
    from canonical.config import config
 
17
    from canonical.pidfile import make_pidfile, pidfile_path
 
18
 
 
19
    # Don't run the Trebuchet if it wasn't asked for.
 
20
    if not config.trebuchet.server.launch:
 
21
        return
 
22
 
 
23
    if not os.path.isdir(config.trebuchet.server.root):
 
24
        os.makedirs(config.trebuchet.server.root, 0700)
 
25
 
 
26
    pidfile = pidfile_path('trebuchet')
 
27
    logfile = config.trebuchet.server.logfile
 
28
    tacfile = os.path.abspath(os.path.join(
 
29
        os.path.dirname(__file__), 'daemons', 'trebuchet.tac'
 
30
        ))
 
31
 
 
32
    ver = '%d.%d' % sys.version_info[:2]
 
33
    args = [
 
34
        "twistd%s" % ver,
 
35
        "--no_save",
 
36
        "--nodaemon",
 
37
        "--python", tacfile,
 
38
        "--pidfile", pidfile,
 
39
        "--prefix", "Trebuchet",
 
40
        "--logfile", logfile,
 
41
        ]
 
42
 
 
43
    if config.trebuchet.server.spew:
 
44
        args.append("--spew")
 
45
 
 
46
    trebuchet_process = subprocess.Popen(args, stdin=subprocess.PIPE)
 
47
    trebuchet_process.stdin.close()
 
48
    # I've left this off - we still check at termination and we can
 
49
    # avoid the startup delay. -- StuartBishop 20050525
 
50
    #time.sleep(1)
 
51
    #if trebuchet_process.poll() != None:
 
52
    #    raise RuntimeError(
 
53
    #            "Trebuchet did not start: %d" % trebuchet_process.returncode
 
54
    #            )
 
55
    def stop_trebuchet():
 
56
        if trebuchet_process.poll() is None:
 
57
            os.kill(trebuchet_process.pid, signal.SIGTERM)
 
58
            trebuchet_process.wait()
 
59
        else:
 
60
            print >> sys.stderr, "*** ERROR: Trebuchet died prematurely!"
 
61
            print >> sys.stderr, "***        Return code was %d" % (
 
62
                    trebuchet_process.returncode,
 
63
                    )
 
64
    atexit.register(stop_trebuchet)
 
65
 
 
66
 
 
67
 
 
68
 
 
69