web2py.exe can not start as windows service

907 views
Skip to first unread message

Iceberg

unread,
Jan 3, 2009, 5:05:37 AM1/3/09
to web2py Web Framework, lim...@gmail.com
Hi everyone,

I followed the instructions in http://mdp.cti.depaul.edu/AlterEgo/default/show/77
But still failed to start web2py.exe as windows service.

Then I found the old post in Apr2008, saying that the windows binary
can not be started as a service.
http://groups.google.com/group/web2py/browse_thread/thread/8382f8fcb7de0534/b7947df750e2a8de?lnk=gst&q=windows+service#b7947df750e2a8de

I am writing to ask whether situation changes since then. Too bad that
web2py.exe can not be deployed on a customer's PC with windows XP but
without python. :-S

Thanks in advance.
Iceberg

mdipierro

unread,
Jan 3, 2009, 6:32:03 PM1/3/09
to web2py Web Framework
If anybody else having problems with this?

@Tim, can you please take a look. I do no have access to a windows
machine until Monday.

Massimo

On Jan 3, 4:05 am, Iceberg <iceb...@21cn.com> wrote:
> Hi everyone,
>
> I followed the instructions inhttp://mdp.cti.depaul.edu/AlterEgo/default/show/77
> But still failed to start web2py.exe as windows service.
>
> Then I found the old post in Apr2008, saying that the windows binary
> can not be started as a service.http://groups.google.com/group/web2py/browse_thread/thread/8382f8fcb7...

Fran

unread,
Jan 4, 2009, 4:16:08 AM1/4/09
to web2py Web Framework
On Jan 3, 11:32 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
> If anybody else having problems with this?

Yes:
python web2py.py -W install
Version 1.55rc3 (2009-01-01 04:54:52)
Traceback (most recent call last):
File "web2py.py", line 5, in <module>
start()
File "C:\Bin\web2py\gluon\widget.py", line 371, in start
web2py_windows_service_handler(['', options.winservice],
options.config)
NameError: global name 'web2py_windows_service_handler' is not defined

I am running Python-2.5.4 & tried installing the PyWin32 extensions
(v212) to see if that was the issue.

I would agree that having this usable from the binary release of
Web2Py would be useful.
I'd be fine with making this a separate download (& even a recipe on
how to build such a binary from the source)

F

mdipierro

unread,
Jan 4, 2009, 8:12:19 AM1/4/09
to web2py Web Framework
are you telling me that the windows binary distribution does not
include pywin32 extensions?

Massimo

Fran

unread,
Jan 4, 2009, 8:59:03 AM1/4/09
to web2py Web Framework
On Jan 4, 1:12 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
> are you telling me that the windows binary distribution does not
> include pywin32 extensions?

Not at all....I've not tried it much...I was just going by what the
original poster had said:
"the windows binary can not be started as a service"
Testing now, I find that 1.54 does the same as the original thread
did:
http://groups.google.com/group/web2py/browse_thread/thread/8382f8fcb7de0534
i.e. Service installs but won't start
Even if I copy an options.py into that folder.
I don't have SSL certs, though...perhaps these are required?

The bigger issue (for me currently) is that the source version won't
install as a service at all:
NameError: global name 'web2py_windows_service_handler' is not defined

F

mdipierro

unread,
Jan 4, 2009, 9:14:42 AM1/4/09
to web2py Web Framework
OK. I will get on the case as soon as I have a windows machine.
Meanwhile I am sure Tim will be able to us more.

Massimo

On Jan 4, 7:59 am, Fran <francisb...@googlemail.com> wrote:
> On Jan 4, 1:12 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > are you telling me that the windows binary distribution does not
> > include pywin32 extensions?
>
> Not at all....I've not tried it much...I was just going by what the
> original poster had said:
> "the windows binary can not be started as a service"
> Testing now, I find that 1.54 does the same as the original thread
> did:http://groups.google.com/group/web2py/browse_thread/thread/8382f8fcb7...

Fran

unread,
Jan 4, 2009, 9:22:14 AM1/4/09
to web2py Web Framework
On Jan 3, 11:32 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
> I do no have access to a windows machine until Monday.

I looked at the service installed by the 1.54 binary & see that it
tries to run:
"C:\web2py\web2py.exe" options

This only runs from the Web2Py folder, otherwise:
Traceback (most recent call last):
File "web2py.py", line 4, in <module>
File "gluon\widget.pyc", line 14, in <module>
IOError: [Errno 2] No such file or directory: 'VERSION'
(This also happens with '-a password' instead of 'options', so isn't
only when trying to launch the UI)

I tried to wrap the .exe into a CMD file so that the .exe is run from
the proper folder.
That works from CMD, but not from services still (even with '-a
password').

'Error 1053: The service did not respond to the start or control
request in a timely fashion'

Nothing logged in the Event Logs other than this &:
"Timeout (30000 milliseconds) waiting for the web2py Service service
to connect."

I'm happy to do more testing/investigation if given pointers.

F

mdipierro

unread,
Jan 4, 2009, 11:07:09 AM1/4/09
to web2py Web Framework
please try from the windows shell..

cd /where/web2py/is/
web2py.exe -S welcome
>>> import winservice

do you get a traceback? what does it say?

Massimo

Fran

unread,
Jan 4, 2009, 11:39:10 AM1/4/09
to web2py Web Framework
On Jan 4, 4:07 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
> please try from the windows shell..
> cd /where/web2py/is/
> web2py.exe -S welcome
> >>> import winservice
> do you get a traceback? what does it say?

Yes:
ImportError: No module named winservice

I get the same in my source version on Trunk (with pywin32 extensions
installed)

F

mdipierro

unread,
Jan 4, 2009, 11:53:05 AM1/4/09
to web2py Web Framework
could you try

import gluon.winservice

?

Fran

unread,
Jan 4, 2009, 3:22:42 PM1/4/09
to web2py Web Framework
On Jan 4, 4:53 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
> could you try
> import gluon.winservice

Yes, that works :)
Both 1.54 bin & 1.55rc4 src

F

Iceberg

unread,
Jan 4, 2009, 9:37:22 PM1/4/09
to web2py Web Framework
Excuse me, but what do you mean "that works"?

In my 1.55rc4 bin, I got:

C:\DOWNLOAD\web2py>web2py -S welcome
...
Version 1.55rc4 (2009-01-02 08:51:19)
Database drivers available: SQLite3, MySQL
WARNING:root:import IPython error, use default python shell
Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit
(Intel)] on win32
>>> import winservice
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "C:\DOWNLOAD\web2py\winservice.py", line 13, in <module>
ImportError: No module named fileutils
>>> import gluon.winservice
>>>

The import succeeded, even so, web2py.exe (bin) refused to be started
as a service.

C:\DOWNLOAD\web2py>web2py -W install
default applications appear to be installed already
web2py Enterprise Web Framework
Created by Massimo Di Pierro, Copyright 2007-2008
Version 1.55rc4 (2009-01-02 08:51:19)
Database drivers available: SQLite3, MySQL
Installing service web2py
Changing service configuration
Service updated

C:\DOWNLOAD\web2py>web2py -W start
default applications appear to be installed already
web2py Enterprise Web Framework
Created by Massimo Di Pierro, Copyright 2007-2008
Version 1.55rc4 (2009-01-02 08:51:19)
Database drivers available: SQLite3, MySQL
Starting service web2py
Error starting service: The service did not respond to the start or

Fran

unread,
Jan 5, 2009, 7:45:11 AM1/5/09
to web2py Web Framework
On Jan 5, 2:37 am, Iceberg <iceb...@21cn.com> wrote:
> Excuse me, but what do you mean "that works"?
> >>> import gluon.winservice
> The import succeeded

That's all I meant.

>, even so, web2py.exe (bin) refused to be started
> as a service.

I think that, with the information I provided, Massimo will be able to
find a fix.

F

Timothy Farrell

unread,
Jan 5, 2009, 9:53:56 AM1/5/09
to web...@googlegroups.com
Sorry guys.  I generally only watch the list at work.  Being it a holiday, I'm a little behind on this issue.  Let me recap the symptoms so you know that I understand...

Source Distribution windows service installs but does not run for Fran.
Neither source nor binary Distribution installs (or runs) for Iceberg.

Is that correct?

Iceberg from your last message, it looks like you're having a path issue.  I'll get a fresh machine and start with the Binary distribution and get back to you.

-tim
-- 
Timothy Farrell <tfar...@swgen.com>
Computer Guy
Statewide General Insurance Agency (www.swgen.com)

Iceberg

unread,
Jan 5, 2009, 10:06:43 AM1/5/09
to web2py Web Framework
Thank for your message, Tim.

For me, I only tried the binary distribution. After web2py.exe -W
install, a service named "web2py Service" appears in the windows
service console. However, web2py.exe -W start does not work. Details
is in my last post (not this one).

Rumors said that starting as a service is only possible for a source
distribution. So I think Fran's problem would be a little easier than
mine. :-S

Thanks for your concern.
Iceberg

Timothy Farrell

unread,
Jan 5, 2009, 10:25:00 AM1/5/09
to web...@googlegroups.com
OK.  Iceberg, yours shouldn't be too difficult, but it's going to take a bit of time.

For Fran and Massimo, I've attached a patched winservice.py  This will show a traceback of the particular error in the Window's Event Viewer.  That should help us narrow the problem.  Fran, you can copy this into your web2py.gluon directory.  Massimo, if you could put this in a checkout and compile it (I don't have the time right now to figure out compiling), Iceberg and I can debug the binary distribution.

Thanks,
  tim
winservice.py

mdipierro

unread,
Jan 5, 2009, 10:54:58 AM1/5/09
to web2py Web Framework
Thank you Tim,

I will do this tonight.

Massimo

P.S. making a new binary distro is as easy as unpacking and replacing
the pyc file in the library.zip file.

Massimo
> Iceberg wrote:Thank for your message, Tim. For me, I only tried the binary distribution. After web2py.exe -W install, a service named "web2py Service" appears in the windows service console. However, web2py.exe -W start does not work. Details is in my last post (not this one). Rumors said that starting as a service is only possible for a source distribution. So I think Fran's problem would be a little easier than mine. :-S Thanks for your concern. Iceberg On Jan5, 10:53pm, Timothy Farrell<tfarr...@swgen.com>wrote:Sorry guys. I generally only watch the list at work. Being it a holiday, I'm a little behind on this issue. Let me recap the symptoms so you know that I understand... Source Distribution windows service installs but does not run for Fran. Neither source nor binary Distribution installs (or runs) for Iceberg. Is that correct? Iceberg from your last message, it looks like you're having a path issue. I'll get a fresh machine and start with the Binary distribution and get back to you. -tim-- Timothy Farrell<tfar...@swgen.com>Computer Guy Statewide General Insurance Agency (www.swgen.com)
>
> [winservice.py3K ]"""
> This file is part of web2py Web Framework (Copyrighted, 2007)
> Developed by Massimo Di Pierro <mdipie...@cs.depaul.edu>
> and Limodou <limo...@gmail.com>
> License: GPL v2
> """
> import time, os, sys, traceback
> import win32serviceutil
> import win32service
> import win32event
> import servicemanager
> import _winreg
> from fileutils import up
>
> __all__=['web2py_windows_service_handler']
>
> class Service(win32serviceutil.ServiceFramework):
> _svc_name_ = '_unNamed'
> _svc_display_name_ = '_Service Template'
> def __init__(self, *args):
> win32serviceutil.ServiceFramework.__init__(self, *args)
> self.stop_event = win32event.CreateEvent(None, 0, 0, None)
> def log(self, msg):
> servicemanager.LogInfoMsg(str(msg))
> def SvcDoRun(self):
> self.ReportServiceStatus(win32service.SERVICE_START_PENDING)
> try:
> self.ReportServiceStatus(win32service.SERVICE_RUNNING)
> self.start()
> win32event.WaitForSingleObject(self.stop_event, win32event.INFINITE)
> except:
> self.log(traceback.format_exc(sys.exc_info))
> self.SvcStop()
> self.ReportServiceStatus(win32service.SERVICE_STOPPED)
> def SvcStop(self):
> self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
> try:
> self.stop()
> except:
> self.log(traceback.format_exc(sys.exc_info))
> win32event.SetEvent(self.stop_event)
> self.ReportServiceStatus(win32service.SERVICE_STOPPED)
> # to be overridden
> def start(self): pass
> # to be overridden
> def stop(self): pass
>
> class Web2pyService(Service):
> _svc_name_ = 'web2py'
> _svc_display_name_ = 'web2py Service'
> _exe_args_ = 'options'
> server = None
>
> def chdir(self):
> try:
> h = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, r'SYSTEM\CurrentControlSet\Services\%s' % self._svc_name_)
> cls = _winreg.QueryValue(h, 'PythonClass')
> dir = os.path.dirname(cls)
> os.chdir(dir)
> return True
> except:
> self.log("Can't change to web2py working path, server is stopped")
> return False
>
> def start(self):
> self.log("web2py server starting")
> if not self.chdir(): return
> if len(sys.argv) == 2:
> opt_mod = sys.argv[1]
> else:
> opt_mod = self._exe_args_
> options = __import__(opt_mod, [], [], '')
> from main import HttpServer
> self.server = HttpServer(ip=options.ip,port=options.port,
> password=options.password,
> pid_filename=options.pid_filename,
> log_filename=options.log_filename,
> ssl_certificate=options.ssl_certificate,
> ssl_private_key=options.ssl_private_key,
> numthreads=options.numthreads,
> server_name=options.server_name,
> request_queue_size=options.request_queue_size,
> timeout=options.timeout,
> shutdown_timeout=options.shutdown_timeout,
> path=options.folder)
> try:
> self.server.start()
> except:
> #self.server.stop()
> self.server = None
> raise
>
> def stop(self):
> self.log("web2py server stopping")
> if not self.chdir(): return
> if self.server:
> self.server.stop()
> time.sleep(1)
>
> def web2py_windows_service_handler(argv=None, opt_file='options'):
> path = os.path.dirname(__file__)
> classstring = os.path.normpath(os.path.join(up(path), 'gluon.winservice.Web2pyService'))
> if opt_file:
> Web2pyService._exe_args_ = opt_file
> win32serviceutil.HandleCommandLine(Web2pyService, serviceClassString=classstring,argv=['', 'install'])
> win32serviceutil.HandleCommandLine(Web2pyService, serviceClassString=classstring,argv=argv)
>
> if __name__=='__main__':
> web2py_windows_service_handler()

Fran

unread,
Jan 5, 2009, 12:18:26 PM1/5/09
to web2py Web Framework
On Jan 5, 3:25 pm, Timothy Farrell <tfarr...@swgen.com> wrote:
> For Fran and Massimo, I've attached a patched winservice.py

Using this version of winservice.py, I managed to get the service
installed & running with src of latest Trunk :)

ImagePath in the registry for the service shows:
"c:\bin\python25\lib\site-packages\win32\PythonService.exe" options

F

Timothy Farrell

unread,
Jan 5, 2009, 12:22:25 PM1/5/09
to web...@googlegroups.com
That's normal.  What was the error in the traceback?  Was it anything that we should code around?

-tim

Fran

unread,
Jan 5, 2009, 4:26:38 PM1/5/09
to web2py Web Framework
On Jan 5, 5:22 pm, Timothy Farrell <tfarr...@swgen.com> wrote:
> That's normal. What was the error in the traceback? Was it anything that we should code around?

I didn't get one - as I say, it's all working for me now with latest
src & your new winservice.py :)
All I see in Event Logs is:
web2py server starting
web2py server stopping

I removed the service & rebooted to try 1.54-bin (reboot required
otherwise service fails to install).
This failed in the old way - service installs but won't start:
System Logs just show:
Timeout (30000 milliseconds) waiting for the web2py Service service to
connect.
The web2py Service service failed to start due to the following
error:
The service did not respond to the start or control request in a
timely fashion.
Nothing in Application Logs.

Yes, I did copy the new winservice.pyc into library.zip 1st.

What I did in both occasions:
Ensure an options.py is present in the web2py folder.
- this has: password = 'password'
(I even tried copying the .pyc from the working src & also tried
coipying that into library.zip)

From the correct folder, run:
..\python25\python web2py.py -W install -a password
or
web2py.exe -W install -a password

src works fine, but not bin.
No extra diagnostics I can see.

F

mdipierro

unread,
Jan 5, 2009, 5:49:14 PM1/5/09
to web2py Web Framework
Fran, just so that I understand:

1.54 without patch src: does not work, bin: does not work
1.54 with patch src: does not work, bin: does not work
1.55 wthout patch src: does not work, bin: does not work
1.55 with patch src: does work, bin: does not work (and no errors)

Is this correct?

Massimo

Iceberg

unread,
Jan 5, 2009, 10:02:37 PM1/5/09
to web2py Web Framework
I tried new winservice.py with 1.55rc4 bin, no surprise, same result
as Fran's 1.54 bin, installed but doesn't work.

I quoted some words here, from an old post which I mentioned in the
first post of this thread:
http://groups.google.com/group/web2py/browse_thread/thread/8382f8fcb7de0534/b7947df750e2a8de?lnk=gst&q=windows+service#b7947df750e2a8de

"pythoncom will register a class, so if you use web2py.exe, it
may cannot get the class file and run. ..... how
to make a zipped python exe file into a windows service ...."

Seems that is the problem need to be solved...... hope this info is
useful....

Iceberg

mdipierro

unread,
Jan 5, 2009, 11:46:37 PM1/5/09
to web2py Web Framework
I do not know what this means. Meanwhile I have incorporated Tim's
patch into

http://mdp.cti.depaul.edu/examples/static/1.55rc2/web2py_win.zip

Hope that helps with tests.

Massimo
> http://groups.google.com/group/web2py/browse_thread/thread/8382f8fcb7...

Iceberg

unread,
Jan 6, 2009, 12:05:42 AM1/6/09
to web...@googlegroups.com
----------------------- Original Message -----------------------
Date: Mon, 5 Jan 2009 20:46:37 -0800 (PST)
Subject: [web2py:14607] Re: web2py.exe can not start as windows service
-------------------

> I do not know what this means. Meanwhile I have incorporated Tim's
> patch into
>
> http://mdp.cti.depaul.edu/examples/static/1.55rc2/web2py_win.zip
>
> Hope that helps with tests.
>
> Massimo

Tried, still can not start as service.

PS: Shouldn't it be 1.55rc4 or even rc5, rather than rc2?

Yarko Tymciurak

unread,
Jan 6, 2009, 2:53:01 AM1/6/09
to web...@googlegroups.com
This seems to work fine as a service for me from source, current tree (as of tonight).

A couple of notes:


I just didn't like the look of "ip = socket.gethostname()"

--> I left this as 127.0.0.1 for my test;  also, left port as 8000 

If anything, I would experiment with this - maybe something like gethostbyname(gethostname())...

I did leave "server_name = socket.gethostname()"  (which, for local test seems harmless enough) but I would probably try something like getfqdn() in a "real" install.

Anyway, start / stop works;

On winXP, using the command line "sc" command shows it as service_name web2py, and that seems a way to modify or delete the service.

I'll try this on a win2003 server tomorrow (now that I've tried this).

one thing I notice:   State:    (STOPPABLE,NOT_PAUSABLE,IGNORES_SHUTDOWN)...

Not sure if we need to flush writes (reason to accept a shutdown)...

Timothy Farrell

unread,
Jan 6, 2009, 9:33:39 AM1/6/09
to web...@googlegroups.com
Well I tried with Massimo's new binary version and got this error message in the event viewer:

The description for Event ID ( 255 ) in Source ( web2py ) cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. You may be able to use the /AUXSOURCE= flag to retrieve this description; see Help and Support for details. The following information is part of the event: web2py server stopping.

I don't really know what to make of this.  The intarweb doesn't have much to say about py2exe-based windows services.  I'll have to come back to this later.

-tim

Fran

unread,
Jan 6, 2009, 11:24:48 AM1/6/09
to web2py Web Framework
On Jan 5, 10:49 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
>1.54 without patch src: does not work, bin: does not work
>1.55 wthout patch src: does not work, bin: does not work
>1.55 with patch src: does work, bin: does not work (and no errors)

Correct

>1.54 with patch src: does not work, bin: does not work

Didn't test
How about Trunk?

F

mdipierro

unread,
Jan 6, 2009, 11:41:05 AM1/6/09
to web2py Web Framework
trunk too.

Yarko Tymciurak

unread,
Jan 7, 2009, 7:36:27 PM1/7/09
to web...@googlegroups.com
My Tests (continuing):

with the latest trunk, on Winserver2003 - I can install, but I cannot start w/ either python or sc command line method - I got:

StartService FAILED 1053:

The service did not respond to the start of control request in a timely fashion.

..... Hmmm...

Iceberg

unread,
Jan 7, 2009, 10:13:22 PM1/7/09
to web...@googlegroups.com
----------------------- Original Message -----------------------
From: mdipierro <mdip...@cs.depaul.edu>
> On Jan 5, 9:02 pm, Iceberg <iceb...@21cn.com> wrote:
> > On Jan6, 5:26am, Fran <francisb...@googlemail.com> wrote:
> > > it's all working for me now with latest
> > > src & your new winservice.py :)
> > > All I see in Event Logs is:
> > > web2py server starting
> > > web2py server stopping
> >
> > > I removed the service & rebooted to try 1.54-bin (reboot required
> > > otherwise service fails to install).
> > > This failed in the old way - service installs but won't start:
> > > System Logs just show:
> > > Timeout (30000 milliseconds) waiting for the web2py Service service to
> > > connect.
> > > The web2py Service service failed to start due to the following
> > > error:
> > > The service did not respond to the start or control request in a
> > > timely fashion.
> > > Nothing in Application Logs.
> >
> > > src works fine, but not bin.
> > > No extra diagnostics I can see.
> >
> > > F
> >
> > I tried new winservice.py with 1.55rc4 bin, no surprise, same result
> > as Fran's 1.54 bin, installed but doesn't work.
> >
> > I quoted some words here, from an old post which I mentioned in the
> > first post of this thread:
> > http://groups.google.com/group/web2py/browse_thread/thread/8382f8fcb7...
> >
> > "pythoncom will register a class, so if you use web2py.exe, it
> > may cannot get the class file and run. ..... how
> > to make a zipped python exe file into a windows service ...."
> >
> > Seems that is the problem need to be solved...... hope this info is
> > useful....
> >
> > Iceberg

>

> I do not know what this means. Meanwhile I have incorporated Tim's
> patch into
>
>

> Massimo

Hi folks,

Just some thoughts.

If bin distribution can not start as a service only because of the possible reason "pythoncom will register a class, so if you use web2py.exe, it may cannot get the class file and run", then, can we just try to build a special bin distribution, in which there is no library.zip, but a directory such as lib/*.pyc, pehaps in this way the winservice.pyc is able to be located by the "pythoncom" or something.

By the way, which wrapper does Massimo use to build web2py binary distribution? The py2exe? It claims it can build windows service.

Sorry for all this blah and not being specific. I know too little in windows service world. :(

Iceberg

mdipierro

unread,
Jan 7, 2009, 10:36:01 PM1/7/09
to web2py Web Framework
If anybody can figure out how to do that I have no objections.
Actually I would prefer not to have the library.zip file.

Massimo
Reply all
Reply to author
Forward
0 new messages