Changeset 311

Show
Ignore:
Timestamp:
06/25/08 00:34:56 (2 months ago)
Author:
heyadayo
Message:

New configuration options for serving static content

Location:
branches/0.5/daemon/orbited
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • branches/0.5/daemon/orbited/config.py

    r294 r311  
    44map = { 
    55    '[global]': { 
    6         'dispatch.enabled': '0' 
     6        'dispatch.enabled': '0', 
     7        'pid.location': '/tmp/orbited.pid' 
    78    }, 
    89    '[logging]': { 
     
    2728    '[global]': { 
    2829        'dispatch.enabled': '1', 
    29         'dispatch.port': '9000' 
     30        'dispatch.port': '9000', 
    3031    }, 
    3132    '[access]': [ 
     
    7374        pass 
    7475    print "Could not locate configuration file. Using default configuration" 
     76    for key, val in defaults.items(): 
     77        if isinstance(map.get(key), dict): 
     78            map[key].update(val) 
     79        else: 
     80            map[key] = val 
    7581    map.update(defaults) 
    7682     
  • branches/0.5/daemon/orbited/control.py

    r291 r311  
    66from start import logger 
    77from start import main as orbited_main 
     8from config import map as config 
     9 
     10pid_location = config['[global]']['pid.location'] 
    811 
    912def start(): 
    1013    print "Starting Orbited Daemon" 
    11     checkpidfile = open('/tmp/orbited.pid', 'a') 
     14     
     15    checkpidfile = open(pid_location, 'a') 
    1216    try: 
    1317        fcntl.lockf(checkpidfile , fcntl.LOCK_EX|fcntl.LOCK_NB) 
     
    5357        # Try to get an exclusive lock on the file.  This will fail 
    5458        # if another process has the file locked. 
    55         pidfile = open('/tmp/orbited.pid', 'w')     
     59        pidfile = open(pid_location, 'w')     
    5660        logger.debug('d3') 
    5761        fcntl.lockf(pidfile, fcntl.LOCK_EX|fcntl.LOCK_NB) 
     
    6771def stop(): 
    6872    print "Stopping Orbited Daemon" 
    69     wpidfile = open('/tmp/orbited.pid', 'a')   
     73    checkpidfile = open(pid_location, 'a')   
    7074    try: 
    71         fcntl.lockf(wpidfile, fcntl.LOCK_EX|fcntl.LOCK_NB) 
    72         fcntl.lockf(wpidfile, fcntl.LOCK_UN) 
     75        fcntl.lockf(checkpidfile, fcntl.LOCK_EX|fcntl.LOCK_NB) 
     76        fcntl.lockf(checkpidfile, fcntl.LOCK_UN) 
    7377    except IOError: 
    7478        pass 
     
    7781        raise SystemExit 
    7882       
    79     rpidfile = open('/tmp/orbited.pid', 'r') 
     83    rpidfile = open(pid_location, 'r') 
    8084    try: 
    8185        pid = int(rpidfile.read()) 
    8286    except ValueError: 
    83         print "Invalid pid file: /tmp/orbited.pid" 
     87        print "Invalid pid file: %s" % (pid_location,) 
    8488        raise SystemExit 
    8589     
     
    9599 
    96100def status(): 
    97     wpidfile = open('/tmp/orbited.pid', 'a')   
     101    wpidfile = open(pid_location, 'a')   
    98102    try: 
    99103        fcntl.lockf(wpidfile, fcntl.LOCK_EX|fcntl.LOCK_NB) 
  • branches/0.5/daemon/orbited/logger/test.py

    r289 r311  
    1 if True: 
     1if False: 
    22    import log 
    33    config = { 
     
    1111        }, 
    1212        '[loggers]': { 
    13             'access': 1, 
     13            'ACCESS': 1, 
    1414            'HTTPDaemon': '2', 
    1515        } 
  • branches/0.5/daemon/orbited/start.py

    r302 r311  
    88#from revolved import RevolvedConnection 
    99logger = get_logger('Daemon') 
     10#if 'INDEX' in config['[static]']: 
     11#    print 'index found', config['[static]']['INDEX'] 
     12#    root = static.File(config['[static]']['INDEX']) 
     13#else: 
    1014root = resource.Resource() 
    1115static_files = static.File(os.path.join(os.path.split(__file__)[0], 'static')) 
     
    1317site = server.Site(root) 
    1418 
     19def setup_static(taken): 
     20    for key, val in config['[static]'].items(): 
     21        if key in taken: 
     22            logger.error("cannot mount static directory with reserved name %s" % key) 
     23            sys.exit(0) 
     24        if key == 'INDEX': 
     25            key = '' 
     26        root.putChild(key, static.File(val)) 
    1527 
    1628def main(): 
     
    2638    if config['[global]']['dispatch.enabled'] == '1': 
    2739        root.putChild('legacy', DispatchFactory()) 
    28          
     40    setup_static(['echo', 'proxy', 'binaryproxy', 'websocket']) 
    2941    for addr in config['[listen]']: 
    3042        url = urlparse.urlparse(addr)