Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Changes between Version 6 and Version 7 of DeployAsWindowsService


Ignore:
Timestamp:
05/13/06 15:43:30 (13 years ago)
Author:
anonymous
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DeployAsWindowsService

    v6 v7  
    6363# 
    6464# The service module defines a single class (TGWindowsService) that contains 
    65 # all of the necessary functionality for running a TurboGears application as 
    66 # a Windows Service. 
     65# the functionality for running a TurboGears application as a Windows Service. 
    6766#  
    6867# To use this class, users must do the following: 
    6968# 1. Download and install the win32all package 
    7069#    (http://starship.python.net/crew/mhammond/win32/) 
    71 # 2. Edit the "USER EDIT SECTION with the proper information. 
     70# 2. Edit the "USER EDIT SECTION" with the proper information. 
     71#    If the standard TurboGears structure is being used (e.g. the one generated by  
     72#    quickstart), and this file is located in the base directory of the TG  
     73#    application (where the dev/prod.cfg file is located), then no edits are required. 
    7274# 3. Open a command prompt and navigate to the directory where this file 
    7375#    is located.  Use one of the following commands to 
     
    8183# 
    8284# Once installed, the service will be accessible through the Services 
    83 # management console just like any other Windows Service.  All exceptions 
    84 # encountered by the TGWindowsService class will be viewable in the 
    85 # Windows event viewer; all application specific exceptions should appear 
    86 # in the stdout/stderr logs. 
     85# management console just like any other Windows Service.  All service  
     86# startup exceptions encountered by the TGWindowsService class will be  
     87# viewable in the Windows event viewer (this is useful for debugging 
     88# service startup errors); all application specific output or exceptions that 
     89# are not captured by the standard TG logging mechanism should  
     90# appear in the stdout/stderr logs. 
    8791# 
    8892# This module has been tested on Windows Server 2000, 2003, and Windows 
    8993# XP Professional. 
    9094# 
    91 # Note 1: This file does not need to exist in the same directory as the code for 
    92 # the TurbGears application.  The TGWindowsService class will find the 
    93 # application's code using the "code_dir" class attribute as defined 
    94 # by the user. 
     95# Note 1: If this file is not located in the application's base directory,  
     96# then make sure to edit the USER EDIT SECTION with the appropriate 
     97# values. 
    9598# 
    9699# Note 2: The cherrypy autoreload functionality will not function when cherrypy 
     
    98101# disable autoreloading before starting the server. 
    99102 
    100 import cherrypy 
    101103import pkg_resources 
    102104pkg_resources.require("TurboGears") 
     105 
     106import turbogears 
     107import cherrypy 
     108cherrypy.lowercase_api = True 
    103109 
    104110import sys 
     
    119125     
    120126    _svc_name_:         The name of the service (used in the Windows registry). 
     127                        DEFAULT: The capitalized name of the current directory. 
    121128    _svc_display_name_: The name that will appear in the Windows Service Manager. 
     129                        DEFAULT: The capitalized name of the current directory.     
    122130    code_dir:           The full path to the base directory of the user's 
    123131                        TG app code (usually where <project_name>-start.py 
    124132                        and the *.cfg files are located). 
     133                        DEFAULT: The directory where this file is located. 
    125134    root_class:         The fully qualified Root class name 
    126135                        (e.g. wiki20.controllers.Root) 
     136                        DEFAULT: <current_dir_name>.controllers.Root 
     137    config_module:      The name of the configuration module. 
     138                        DEFAULT: <current_dir_name>.config 
    127139    log_dir:            The desired location of the stdout and stderr 
    128140                        log files. 
    129  
     141                        DEFAULT: code_dir 
     142           
    130143    For information on installing the application, please refer to the 
    131144    documentation at the end of this module or navigate to the directory 
     
    133146    prompt. 
    134147    """ 
     148    current_dir = os.path.split(__file__)[0] 
     149    default_project_name = os.path.split(current_dir)[1] 
    135150 
    136151    # -- START USER EDIT SECTION 
    137152    # -- Users must edit this section before installing the service. 
    138     _svc_name_ = ''          # (Required) The name of the service. 
    139     _svc_display_name_ = ''  # (Required) The Service Manager display name. 
    140     code_dir = r''           # (Required) The base directory of the TG app code. 
    141     root_class = ''          # (Required) The fully qualified Root class name. 
    142     log_dir = r''            # (Optional) The log directory. Default = code_dir. 
     153    _svc_name_ = '%s' % default_project_name.capitalize()           # The name of the service. 
     154    _svc_display_name_ = '%s' % default_project_name.capitalize()   # The Service Manager display name. 
     155    code_dir = current_dir                                          # The base directory of the TG app code.         
     156    root_class = '%s.controllers.Root' % default_project_name       # The fully qualified Root class name. 
     157    config_module = '%s.config' % default_project_name              # The name of the config module 
     158    log_dir = r''                                                   # The log directory for the stderr and  
     159                                                                    # stdout logs. Default = code_dir. 
    143160    # -- END USER EDIT SECTION 
    144161     
     
    148165        self.ReportServiceStatus(win32service.SERVICE_START_PENDING) 
    149166        self.tg_init() 
    150         cherrypy.root = self.root() 
    151167        self.ReportServiceStatus(win32service.SERVICE_RUNNING) 
    152         cherrypy.server.start() 
     168        turbogears.start_server(self.root()) 
    153169     
    154170    def SvcStop(self): 
     
    180196            TGWindowsService.log_dir = '.' 
    181197 
    182         if exists(join(TGWindowsService.code_dir, "setup.py")): 
    183             cherrypy.config.update(file="dev.cfg") 
     198        if exists(join(dirname(__file__), "setup.py")): 
     199            turbogears.update_config(configfile="dev.cfg", 
     200                modulename=TGWindowsService.config_module) 
    184201        else: 
    185             cherrypy.config.update(file="prod.cfg") 
     202            turbogears.update_config(configfile="prod.cfg", 
     203                modulename=TGWindowsService.config_module) 
    186204 
    187205        # Set environment to production to disable auto-reload. 
     
    214232    # For a full list of arguments, simply type "service.py". 
    215233    win32serviceutil.HandleCommandLine(TGWindowsService) 
    216  
    217234}}} 
    218235