Remove old service script folder.

This commit is contained in:
Matthew Stratford 2020-10-29 19:59:26 +00:00
parent 2623c75627
commit e8d9a7492b
No known key found for this signature in database
GPG key ID: 5F50E4308A3416E8
4 changed files with 0 additions and 148 deletions

View file

@ -1,98 +0,0 @@
'''
SMWinservice
by Davide Mastromatteo
Base class to create winservice in Python
-----------------------------------------
Instructions:
1. Just create a new class that inherits from this base class
2. Define into the new class the variables
_svc_name_ = "nameOfWinservice"
_svc_display_name_ = "name of the Winservice that will be displayed in scm"
_svc_description_ = "description of the Winservice that will be displayed in scm"
3. Override the three main methods:
def start(self) : if you need to do something at the service initialization.
A good idea is to put here the inizialization of the running condition
def stop(self) : if you need to do something just before the service is stopped.
A good idea is to put here the invalidation of the running condition
def main(self) : your actual run loop. Just create a loop based on your running condition
4. Define the entry point of your module calling the method "parse_command_line" of the new class
5. Enjoy
'''
import socket
import win32serviceutil
import servicemanager
import win32event
import win32service
class SMWinservice(win32serviceutil.ServiceFramework):
'''Base class to create winservice in Python'''
_svc_name_ = 'pythonService'
_svc_display_name_ = 'Python Service'
_svc_description_ = 'Python Service Description'
@classmethod
def parse_command_line(cls):
'''
ClassMethod to parse the command line
'''
win32serviceutil.HandleCommandLine(cls)
def __init__(self, args):
'''
Constructor of the winservice
'''
win32serviceutil.ServiceFramework.__init__(self, args)
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
socket.setdefaulttimeout(60)
def SvcStop(self):
'''
Called when the service is asked to stop
'''
self.stop()
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
win32event.SetEvent(self.hWaitStop)
def SvcDoRun(self):
'''
Called when the service is asked to start
'''
self.start()
servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,
servicemanager.PYS_SERVICE_STARTED,
(self._svc_name_, ''))
self.main()
def start(self):
'''
Override to add logic before the start
eg. running condition
'''
pass
def stop(self):
'''
Override to add logic before the stop
eg. invalidating running condition
'''
pass
def main(self):
'''
Main class to be ovverridden to add logic
'''
pass
# entry point of the module: copy and paste into the new module
# ensuring you are calling the "parse_command_line" of the new created class
if __name__ == '__main__':
SMWinservice.parse_command_line()

View file

@ -1,2 +0,0 @@
python C:\Users\matth\Documents\GitHub\bapsicle\install\windows_service.py debug
TIMEOUT 10

View file

@ -1,12 +0,0 @@
cd /D "%~dp0"
pip install -r requirements.txt
pip install -r requirements-windows.txt
pip install -e ..\
python windows_service.py install
mkdir "C:\Program Files\BAPSicle"
cd "C:\Program Files\BAPSicle\"
mkdir state
copy "C:\Program Files\Python37\Lib\site-packages\pywin32_system32\pywintypes37.dll" "C:\Program Files\Python37\Lib\site-packages\win32\"
TIMEOUT 10

View file

@ -1,36 +0,0 @@
from server import BAPSicleServer
from pathlib import Path
from SMWinservice import SMWinservice
import time
import multiprocessing
import sys
sys.path.append("..\\")
class BAPScileAsAService(SMWinservice):
_svc_name_ = "BAPSicle"
_svc_display_name_ = "BAPSicle Server"
_svc_description_ = "BAPS development has been frozen for a while, but this new spike of progress is dripping."
def start(self):
self.isrunning = True
self.server = multiprocessing.Process(target=BAPSicleServer).start()
def stop(self):
print("stopping")
self.isrunning = False
try:
self.server.terminate()
self.server.join()
except:
pass
def main(self):
while self.isrunning:
time.sleep(1)
print("BAPSicle is running.")
if __name__ == '__main__':
BAPScileAsAService.parse_command_line()