RFC: Linux *-Service Cmdlets via D-Bus#411
Open
peppekerstens wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Linux *-Service Cmdlets via D-Bus
This RFC proposes implementing the
*-Servicecmdlets for Linux (Get-Service,Start-Service,Stop-Service,Restart-Service,Set-Service,New-Service,Remove-Service) using the systemd D-Bus API (org.freedesktop.systemd1) instead of shelling out tosystemctl.Motivation
Currently,
*-Servicecmdlets are Windows-only. Linux users must usesystemctlviaInvoke-ExpressionorStart-Process, which breaks pipeline input, object output, andShouldProcesssafety.User Experience
The cmdlets behave identically to their Windows counterparts, returning
LinuxServiceControllerobjects that mirrorSystem.ServiceProcess.ServiceControllerproperties.Specification
Implementation Details
Tmds.DBus.Protocolto communicate withorg.freedesktop.systemd1. Nosystemctlsubprocess is spawned.LinuxServiceController(inheritsSystem.ComponentModel.Component), matchingServiceControlleron Windows.Name,DisplayName,Status,StartType,ActiveState,SubState,ServiceName."CmdletName requires root privileges. Use 'sudo pwsh'."-WhatIfand-Confirm.Get-Service -Namesupports wildcards (*,?).Get-Servicefilters out template units (e.g.,systemd-journald@.service) that cannot be started directly.Cmdlet Mapping
Get-ServiceListUnits,ListUnitFilesStart-ServiceStartUnit(name, "replace")Stop-ServiceStopUnit(name, "replace")Restart-ServiceRestartUnit(name, "replace")Set-ServiceEnableUnitFiles/DisableUnitFiles-StartupTypeNew-ServiceReload+EnableUnitFiles.servicefile in/etc/systemd/system/Remove-ServiceStopUnit+DisableUnitFiles+ File delete +ReloadPlatform Branching
The implementation is guarded by
#if UNIX. On Windows, the existingServiceControllerimplementation is used. On Linux, the D-Bus implementation is active.Error Handling
ErrorRecordwith categoryResourceUnavailable.InvalidOperationExceptionwith message"CmdletName requires root privileges. Use 'sudo pwsh'."Get-Servicereturns no output (matches Windows behavior).Alternate Proposals and Considerations
Subprocess (
systemctl)Using
systemctlviaProcessStartInfois simpler but introduces:D-Bus is the native API for systemd.
systemctlis a CLI wrapper around the same D-Bus calls. Using D-Bus directly is the Linux equivalent of using Win32 APIs on Windows.Third-Party Modules
Modules like
PSSystemdexist but are not cross-platform and do not match the Windows cmdlet surface. This proposal aligns with the goal of Windows-compatible cmdlets on Linux.References
This change is