PowerShell icon indicating copy to clipboard operation
PowerShell copied to clipboard

PowerShell core on Linux - Get-Service should mimic linux "service" command.

Open MaximoTrinidad opened this issue 9 years ago • 4 comments

Steps to reproduce

Type the cmdlet: Get-Service ssh Or, Stop-Service ssh Or, Start-Service ssh

Expected behavior

PowerShell => Linux Get-Service ssh => service --status-all Start-Service ssh => service ssh start Stop-Service ssh => service ssh stop

Actual behavior

Any of the three cmdlets will give the following errors: xxx-service : The term 'xxx-service' is not recognized as the name of a cmdlet, function, script file, or operable program. xx-service_2017-04-17_13-59-44

Environment data

Linux Ubuntu Desktop 16.04.2

PS /home/maxt> $PSVersionTable                                                                                          
Name                           Value
----                           -----
PSVersion                      6.0.0-alpha
PSEdition                      Core
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   3.0.0.0
GitCommitId                    v6.0.0-alpha.18
CLRVersion
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

MaximoTrinidad avatar Apr 17 '17 18:04 MaximoTrinidad

Except that service is only available on systemd machines. That's why this is tricky. We basically need to implement this behavior two (or three or four) times.

joeyaiello avatar Apr 17 '17 18:04 joeyaiello

I agree as we start using powershell for managing azure deployments which may or may not be windows

rahulguha avatar May 20 '18 15:05 rahulguha

Hi any progress :-)

*-Service is probably the most important cmdlets to be ported to linux, Most my use of powershell is to create and manage services because it is so simple compared to sc, nssm.exe, sysinit and systemd. Systemd is now used by most linuxes. I'm eagerly awaiting this.

Even Raspbian have systemd

# cat /proc/cpuinfo | grep model | head -1
model name      : ARMv7 Processor rev 5 (v7l)
# cat /etc/debian_version
9.1
# systemctl | grep service | wc -l
41
# pwsh
PowerShell 6.1.0
Copyright (c) Microsoft Corporation. All rights reserved.
https://aka.ms/pscore6-docs
Type 'help' to get help.

PS /root> Get-Command | Measure-Object -line
Lines Words Characters Property
----- ----- ---------- --------
  323

PS /root> Get-Command | select-string -Pattern "Service"
PS /root>

fenchu avatar Jan 25 '19 10:01 fenchu

Hi, any new progress with implementing Start-Service for Linux? I would really appreciate it.

pat0s avatar Sep 07 '22 11:09 pat0s

6 years later and no change on this?

brolifen avatar May 27 '23 06:05 brolifen

There is the nxtools module that has wrappers for common Linux utilities.

ThomasNieto avatar Aug 18 '23 15:08 ThomasNieto

https://github.com/PowerShell/PowerShell/issues/3582#issuecomment-294551258

@joeyaiello, almost all distributions nowadays use systemd for that same reason. Trying to automate initialization scripts across distributions was hellish until systemd standardized the API through its marketshare. Consequently, I would wholeheartedly accept an implementation which solely supported systemd.

Proponents of SysVInit etcetera could request or implement their own if it had any kind of extension system built in. Otherwise, they could simply call the binaries without utilizing PowerShell's obfuscation. My expectation is that very few distributions which don't utilize systemd have a significant PowerShell userbase.

Don't allow perfection to be the enemy of good.

RokeJulianLockhart avatar Dec 17 '23 12:12 RokeJulianLockhart

https://github.com/PowerShell/PowerShell/issues/3582#issue-222187394

@MaximoTrinidad, why do you propose service rather than calling systemctl?

RokeJulianLockhart avatar Dec 17 '23 14:12 RokeJulianLockhart

Okay - I thought there was something wrong with my PowerShell install onto Debian 12 - so it is a bit reassuring to see that I'm not the only person struggling with the "Get-Service" command.

If I'm understanding this correctly, there is no workaround for this, aside from utilizing nxtools? I ask, because even after installing it, there was no change when attempting to run command.

(I'm new to learning how to work with PowerShell - so thanks for your patience!)

priestapostate1208 avatar Feb 07 '24 14:02 priestapostate1208