Issue #396 resolved

Additions to WindowsService21 Wiki page

Anonymous created an issue

= Installation = Save this source code into a file called ! and then type: {{{ python }}} You will see a list of options for installing, removing, starting, and stopping your service.

To install your new service type: {{{ python install }}} Then type: {{{ python start }}} to start it. You can also start and stop the service by going to the Start menu, Administrative Tools, Services, and looking for the name of your service.

= Running Your CherryPy Application = When you are ready to turn your own CherryPy application into a service, you will probably encounter several things that the simple example above does not.

== Working Directory == When your service starts, the working directory is likely to be somewhere different than when you launch your CherryPy application from the command line. You will need to use full path's to configuration files, etc.

Also be aware of any static content that CherryPy is serving. Any "staticFilter.dir" lines in your config file will need a full path as well.

Another way around this is to add "os.chdir('c:\path\to\CherryPy\application')" just before "cherrypy.server.start()". This will change your working directory to the place where your application is installed.

== No Autoreloader == The autoloader doesn't play nice as a service. It watches for stuff to change, and then tries to restart the application. Which fails. The "server.environment = 'production'" configuration option is supposed to turn off the autoreloader, but that may change in the future. Make sure you have {{{ [global] autoreload.on = False }}} in your configuration file.

= Debugging a Windows Service = It isn't very easy to debug a windows service. Make sure your application runs from the command line with no problems before spending any time trying to get it to work as a service. If your application works from the command line, but doesn't work as a service, these tips may help you see what is wrong.

== Firewalls == Beware of the XP Service Pack 2 firewall. If it is on, it will block programs from listening on ports. When you run your CherryPy application from the command line, it will pop up a window and ask you if you want to grant access to the program "python.exe". You say yes, thinking this will work for both the command line and the service. Nope. The service actually runs the executeable "pythonservice.exe". If the firewall is blocking that program from opening ports, your service will silently fail to start. This is probably also true for ZoneAlarm, BlackIce Defender, and other firewall programs.

== Look in the Event Viewer == Go to the Start Menu, Administrative Tools, Event Viewer, and click on "Applications". Look for events with a source that is the name of your service.

== Make sure you have a log file == CherryPy will log stuff to disk if you put the following in your configuration file: {{{ [global] server.logFile = 'c:\path\to\logfile' }}} Look in the log file and see if anything looks strange.

== Log tracebacks == Tracebacks may help you see where your application is failing. Put this in your config file: {{{ [global] server.logTracebacks = True }}} Restart your service, and look in the log file again.

Reported by

Comments (2)

  1. Log in to comment