Asp.Net Core应用第二次部署至Beanstalk出现Errno 13权限拒绝如何解决?
问题根因
首次部署时服务还未运行,目标路径没有被占用的文件,所以执行正常。第二次部署时,之前注册启动的georgiservice Windows服务处于运行状态,对应的GeorgiService.dll文件被服务进程锁定,Beanstalk执行sources配置直接覆盖C:\service路径下的文件时,就会触发权限拒绝错误。
解决方法
修改你的.ebextensions配置,调整部署逻辑避免文件被占用的问题,以下两种方案选其一即可:
方案一:新增services配置段,让Beanstalk自动管理服务启停
修改02-winservice.config,新增services配置,告知Beanstalk在部署更新前自动停止对应服务,部署完成后再重新启动,同时修正原有命令的拼写错误:
Resources: AWSEBAutoScalingGroup: Metadata: AWS::CloudFormation::Authentication: S3Auth: type: "s3" buckets: ["temp-poc-bucket"] roleName: "temp_poc_test_role" sources: "C:/service/": https://temp-poc-bucket.s3.us-west-2.amazonaws.com/GeorgiService.zip # 新增services配置,让EB自动管理服务生命周期 services: windows: georgiservice: enabled: true ensureRunning: true commands: stop-previous-service: command: sc.exe stop georgiservice ignoreErrors: true waitAfterCompletion: 5 create-service: command: sc.exe create georgiservice binpath= "C:\service\GeorgiService.exe" ignoreErrors: true waitAfterCompletion: 0 # 修正原配置的拼写错误 srvice -> service start-service: command: sc.exe start georgiservice waitAfterCompletion: 0 ignoreErrors: true
方案二:先下载到临时目录,停服后再覆盖正式路径
如果方案一不生效,可以调整解压逻辑,先把压缩包下载到临时目录,停服释放文件锁后再覆盖正式路径,修改02-winservice.config如下:
Resources: AWSEBAutoScalingGroup: Metadata: AWS::CloudFormation::Authentication: S3Auth: type: "s3" buckets: ["temp-poc-bucket"] roleName: "temp_poc_test_role" # 先解压到临时目录,不直接触碰运行中的服务文件 sources: "C:/temp_service/": https://temp-poc-bucket.s3.us-west-2.amazonaws.com/GeorgiService.zip commands: 00-stop-service: command: sc.exe stop georgiservice ignoreErrors: true waitAfterCompletion: 5 01-clear-old-files: command: rmdir /s /q C:\service ignoreErrors: true 02-copy-new-files: command: xcopy C:\temp_service\* C:\service\ /E /H /C /R /Y /I waitAfterCompletion: 3 03-create-service: command: sc.exe create georgiservice binpath= "C:\service\GeorgiService.exe" ignoreErrors: true waitAfterCompletion: 0 04-start-service: command: sc.exe start georgiservice waitAfterCompletion: 0 ignoreErrors: true
额外注意事项
如果你的服务停止需要更长时间,可以适当调大对应命令的waitAfterCompletion数值,单位为秒,确保文件锁完全释放后再执行文件覆盖操作。
内容的提问来源于stack exchange,提问作者Georgi Koemdzhiev
相关产品推荐
相关产品推荐

