How to stop a windows service using greengrass custom component

0

I have below simple python script that stops a service running by administrator. When I run this script manually on windows core device as administrator it works perfectly.

**import win32serviceutil service_name = "eMAROffline" # replace with the name of the service you want to stop try: win32serviceutil.StopService(service_name) print(f"Service {service_name} stopped successfully.") except Exception as e: print(f"Error stopping service {service_name}: {e}") ** My requirement to stop service using AWS IoT Greengrass component deployment. When I deploy this script as Greengrass component am getting the below error.

com.mx.stopService: stdout. Error stopping service eMAROffline: (5, 'OpenSCManager', 'Access is denied.') I googled this error and it seems the issue is related to permissions. Greengrass component user ggc_user wouldn't have privileges' to stop services running under administrator.

Any suggestions/thoughts how can make this work?

I added ggc_user in Administrators group but no luck.

Full log: 2023-04-18T15:02:50.077Z [INFO] (pool-2-thread-58) com.mx.stopService: shell-runner-start. {scriptName=services.com.mx.stopService.lifecycle.Run, serviceName=com.mx.stopService, currentState=STARTING, command=["python C:\greengrass\v2\packages\artifacts-unarchived\com.mx.stopService\1.0.0..."]} 2023-04-18T15:02:51.120Z [INFO] (Copier) com.mx.stopService: stdout. Error stopping service eMAROffline: (5, 'OpenSCManager', 'Access is denied.'). {scriptName=services.com.mx.stopService.lifecycle.Run, serviceName=com.mx.stopService, currentState=RUNNING} 2023-04-18T15:02:51.152Z [INFO] (Copier) com.mx.stopService: Run script exited. {exitCode=0, serviceName=com.mx.stopService, currentState=RUNNING}

preguntada hace un año235 visualizaciones
1 Respuesta
0

You can select which user run the Greengrass component by setting the runWith.windowsUser property in the component configuration to a user that has permissions to perform the required operation.

https://docs.aws.amazon.com/greengrass/v2/developerguide/create-deployments.html

AWS
EXPERTO
respondido hace un año

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas