Add Windows service registration support to azure-cns #4091
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Overview
This PR adds Windows service registration support to azure-cns, enabling it to self-register as a Windows service for automatic startup and recovery. This addresses the requirements from the Azure Batch team who need azure-cns to automatically restart on crashes and start automatically when VMs reboot.
Changes
Core Implementation
Windows Service Handler (
cns/service/service_windows.go): Implements Windows service functionality usinggolang.org/x/sys/windows/svcpackagePlatform Stub (
cns/service/service_other.go): Non-Windows platforms return appropriate errors when service operations are attemptedService Integration (
cns/service/main.go):--servicecommand-line flag withinstall,uninstall, andrunactionsConfiguration (
common/config.go): Added service-related command-line option constantsTesting
cns/service/service_test.go): Tests for service functions on non-Windows platformsDocumentation
cns/README.md): General documentation with Windows service overviewcns/doc/windows-service.md): Comprehensive guide including:Usage
Install and Start Service
View Service Logs
Uninstall Service
Service Configuration
The service is registered with the following settings:
azure-cnsBenefits
Platform Compatibility
Testing Notes
Fixes #[issue_number]
Original prompt
Fixes #4046
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.