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}

질문됨 일 년 전235회 조회
1개 답변
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
전문가
답변함 일 년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠