Why this question?
As a noob to programming with windows services, myself and a colleague were unable to get our service to start via the use of the net start command. We eventually found a problem that allowed the service to start, but I lack understanding about why our solution worked, I believe others may suffer this problem too, so I am posting the question and an answer which covers how we resolved our situation, I hope others more experienced and knowledgable will contribute more complete answers.
The Question I really want answered
Why it is that a windows service, specifically one based on python, will fail to start, but not return an error.
The most difficult part of this problem we had to overcome was not having an error returned, we looked in the events log, the command prompt where the net start command was used, but there was no error information to be had.
Problem Details
The problem occurred whilst attempting to create a windows service based on a python module, we followed the method provided here to install a windows service that uses our python module.
Starting the service like this worked (more on running here)
python service_definition.py debug
The code in service_definintion.py is from the examples in the links above, repeated below
import time
import random
from pathlib import Path
from SMWinservice import SMWinservice
import cress
from cress import server_interface
import sys
class server_interface_backgndproc(SMWinservice):
_svc_name_ = "server_interface_backgndproc"
_svc_display_name_ = "CrowdRender SIP"
_svc_description_ = "CrowdRender Server Interface Process"
def start(self):
self.isrunning = True
sys.argv.append(["--",
# "--cr_session_type", 'agent',
"--cr_cress_mode", "SIP",
])
def stop(self):
self.isrunning = False
def main(self):
i = 0
## while self.isrunning:
server_interface.CRMachineManager()
returns
#while self.isrunning:
if __name__ == '__main__':
server_interface_backgndproc.parse_command_line()
When it came time to start the service using either net start 'service name' or using the services panel in task manager, the service did not start. When using net start we got the following output;
net start 'service name'
Windows could not start the 'service name' service on Local Computer.
The service did not return an error.
This could be an internal Windows error or an internal service error.
If the problem persists, contact your system administrator.