Below is my shellscript:
& 'C:\files\service_file.exe' install
#Start the windows service
& 'C:\file\service_file.exe' start --env "D:\full_project\device\config\windows.env"
I used pyinstaller to create service_file.exe and 'start' arg is working fine but does not support env path if included
I get path not found error, even after giving the env.
below is my service_file.py
import os
import win32serviceutil
import win32service
import servicemanager
import argparse
class MyService:
def stop(self):
self.running = False
def run(self):
application_path = os.path.dirname(sys.executable)
os.chdir(application_path)
def load_env(envFile):
global env_obj
env_obj = Environment(envFile)
return env_obj
parser = argparse.ArgumentParser(description="testing")
parser.add_argument("--env")
parser.add_argument("--log")
args = parser.parse_args()
env_obj = load_env(args.env)
db_agent(env_obj)
db_agent_download(env_obj)
client_agent(env_obj)
init_scheduler()
app = rest_api(env_obj)
app.run(port=env_obj.rest_api_port, host="0.0.0.0")
class MyServiceFramework(win32serviceutil.ServiceFramework):
_svc_name_ = 'DeviceAgent'
_svc_display_name_ = 'Device Agent Service'
def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
self.service_impl.stop()
self.ReportServiceStatus(win32service.SERVICE_STOPPED)
def SvcDoRun(self):
self.service_impl = MyService()
self.ReportServiceStatus(win32service.SERVICE_START_PENDING)
self.ReportServiceStatus(win32service.SERVICE_RUNNING)
self.service_impl.run()
def Main():
if len(sys.argv) == 1:
print("this is if")
servicemanager.Initialize()
servicemanager.PrepareToHostSingle(MyServiceFramework)
servicemanager.StartServiceCtrlDispatcher()
else:
print("this is else",sys.argv)
win32serviceutil.HandleCommandLine(MyServiceFramework)
if __name__ == '__main__':
Main()
What should i do ? how can i run the shellscript along with env. I want to know how i should pass the argument for env