Error while installing windows service in Amazon EC2 Windows Instance

0

Hi AWS, I am trying to deploy a windows service using CI/CD pipeline with the help of GitHub Actions. The Windows service is written in .NET Framework 4.7 with C#.

Here is the code repo: https://github.com/arjungoel/WindowsServiceDemo

Pipeline Code:

name: "Deploying a CI/CD for Windows Service using GitHub Actions"

on:
  workflow_dispatch:
  push:
    branches: [ "master" ]
  pull_request:
    branches: [ "master" ]

jobs:
  build:

         runs-on: windows-latest
         defaults:
           run:
             shell: cmd

         steps:
         - name: Checkout code repository
           uses: actions/checkout@v3
      
         - name: Setup MSBuild
           uses: microsoft/setup-msbuild@v1

         - name: Setup NuGet
           uses: NuGet/setup-nuget@v1.0.5

         - name: Restore Packages
           run: nuget restore WindowsServiceDemo.sln

         - name: Build solution
           run: msbuild WindowsServiceDemo.sln /p:Configuration=Release /p:DeployOnBuild=true
            
         - name: Set AWS credentials
           uses: aws-actions/configure-aws-credentials@v1
           with:
             aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
             aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
             aws-region: ${{ secrets.AWS_REGION }}

         - name: Upload the files from bin folder to S3 bucket
           run: |
             aws s3 cp D:\a\WindowsServiceDemo\WindowsServiceDemo\WindowsServiceDemo\bin\Release\WindowsServiceDemo.exe.config s3://dotnet-cicd-bucket/
             aws s3 cp D:\a\WindowsServiceDemo\WindowsServiceDemo\WindowsServiceDemo\bin\Release\WindowsServiceDemo.exe s3://dotnet-cicd-bucket/
             aws s3 cp D:\a\WindowsServiceDemo\WindowsServiceDemo\WindowsServiceDemo\bin\Release\WindowsServiceDemo.pdb s3://dotnet-cicd-bucket/

  deploy:
      needs: build
      runs-on: [ self-hosted, Windows, X64 ]
      defaults:
        run:
          shell: cmd
    
      steps:
    
       - name: Set AWS credentials
         uses: aws-actions/configure-aws-credentials@v1
         with:
           aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
           aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
           aws-region: ${{ secrets.AWS_REGION }}

       - name: Download the zip file from S3 to EC2 folder
         shell: powershell
         run: |
           C:\"Program Files"\Amazon\AWSCLIV2\aws s3 cp s3://dotnet-cicd-bucket/WindowsServiceDemo.exe "C:\actions-runner\_work"
           C:\"Program Files"\Amazon\AWSCLIV2\aws s3 cp s3://dotnet-cicd-bucket/WindowsServiceDemo.exe.config "C:\actions-runner\_work"
           C:\"Program Files"\Amazon\AWSCLIV2\aws s3 cp s3://dotnet-cicd-bucket/WindowsServiceDemo.pdb "C:\actions-runner\_work"
         
       - name: Install a service using command prompt
         shell: cmd
         run: |
           cd C:\Windows\System32 & "C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe" "C:\actions-runner\work\WindowsServiceDemo.exe"
  
          

  #    # - name: Display the service status
     #   shell: powershell
     #   run: Start-Process powershell Get-Service -Verb RunAs

The build job is running on GitHub Hosted Runner and the deploy job is running on Self-Hosted runner which is configured on Amazon EC2 Windows instance. Now the problem is at the installation step I am getting this error:

Exception occurred while initializing the installation: System.IO.FileNotFoundException: Could not load file or assembly 'file:///C:\actions-runner\work\WindowsServiceDemo.exe' or one of its dependencies. The system cannot find the file specified.. Error: Process completed with exit code -1.

and I believe this is a general permission issue in windows but I am not aware of how to fix it. Is there something which I have to enable in the OS settings manually or any small change in the code can help me get rid off this issue. I have tried to find a post on Stack Overflow or YouTube but nothing helped and I have already spent more than 15 hours to get rid off this issue but no luck yet!

This issue is an extension to the issue already opened i.e. https://repost.aws/questions/QUmNS6bap2TIOiy_Ca6XpDog/windows-service-is-not-found-in-t2-micro-ec2-windows-instance

The instance size is not an issue as I have tried it with a larger instance size like t2.large.

Please help as I need to fix this ASAP!

profile picture
Arjun
asked 7 months ago324 views
2 Answers
1

I found the solution for this. You need to enable this setting under the Log On option for GitHub Actions Runner service under the Services.msc console.

GitHub Actions Runner Service

profile picture
Arjun
answered 7 months ago
0

One thing I notice is that in the step, "Download the zip file from S3 to EC2 folder", you are copying from S3 into the following folder:

"C:\actions-runner\_work"

But then you try to install from the following location:

"C:\actions-runner\work\WindowsServiceDemo.exe"

Note that you copied into _work with a leading "_" character, but you're not using that underscore character in the install command. This is possibly what is causing your error.

profile pictureAWS
Kirk_D
answered 7 months ago
  • Hi Kirk_D, I have provided the solution below to get rid off the error.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions