Windows service is not found in `t2.micro` EC2 Windows instance

0

Hi AWS, I am deploying a windows service using CI/CD pipeline in EC2 Windows instance. The instance size is t2.micro and using 2022 Base AMI. The weird part is the commands are executing successfully but the service name is not found in service.msc console but when I am doing the same manually in the instance it is working.

I have locked this as an issue in the past and the link for the same is https://repost.aws/questions/QUHMSFANnXSIG8vAn_VmQnmg/service-name-is-not-showing-in-services-console-ec2-windows-instance

Can you please confirm why is this happening. Is this because of the instance size or something else. Please help as I need to get it fixed ASAP.

Thanks

2 Answers
0

Hi Arjun!

Looks like you're using GitHub Actions to deploy your pipeline, I recommend watching GitHub actions logs in debug mode when the stage runs, and check that it indeed works. Resource: https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/enabling-debug-logging

Alternatively, it could be an issue with using a t2.micro sized instance, as they are the smallest GP instance in EC2, it's very possible that service registration is failing or getting killed before complication.

profile picture
answered 7 months ago
  • Hi Brian Chew, the instance size is not an issue as I have tried the same with t2.large but the same issue persists.

0

I have tweaked the pipeline code and got some other error. Can someone help me in fixing it. Here is the 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 .exe to S3 bucket
         run: aws s3 cp D:\a\WindowsServiceDemo\WindowsServiceDemo\WindowsServiceDemo\bin\Release\WindowsServiceDemo.exe 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"
         
      - name: Install a service using Powershell
        shell: powershell
        run: |
          Set-Location C:\Windows\System32
          Set-Location C:\Windows\Microsoft.NET\Framework\v4.0.30319
          & "C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe" "C:\actions-runner\_work\WindowsServiceDemo.exe"

and here is the error:

Affected parameters are: logtoconsole = logfile = C:\actions-runner_work\WindowsServiceDemo.InstallLog assemblypath = C:\actions-runner_work\WindowsServiceDemo.exe Installing service Service1... Creating EventLog source Service1 in log Application...

An exception occurred during the Install phase. System.Security.SecurityException: The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security, State.

The Rollback phase of the installation is beginning. See the contents of the log file for the C:\actions-runner_work\WindowsServiceDemo.exe assembly's progress. The file is located at C:\actions-runner_work\WindowsServiceDemo.InstallLog. Rolling back assembly 'C:\actions-runner_work\WindowsServiceDemo.exe'. Affected parameters are: logtoconsole = logfile = C:\actions-runner_work\WindowsServiceDemo.InstallLog assemblypath = C:\actions-runner_work\WindowsServiceDemo.exe Restoring event log to previous state for source Service1. An exception occurred during the Rollback phase of the System.Diagnostics.EventLogInstaller installer. System.Security.SecurityException: The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security, State. An exception occurred during the Rollback phase of the installation. This exception will be ignored and the rollback will continue. However, the machine might not fully revert to its initial state after the rollback is complete.

The Rollback phase completed successfully.

The transacted install has completed. The installation failed, and the rollback has been performed. Error: Process completed with exit code 1.

profile picture
Arjun
answered 7 months ago

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