Skip to content

Linux Service module #454

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

using namespace System.Collections.Generic

[DscResource()]
class SystemctlService
{
[DscProperty(Key)]
[string] $Unit

[DscProperty()]
[string] $Load

[DscProperty()]
[string] $Active

[DscProperty()]
[string] $Sub

[DscProperty()]
[string] $Description

[void] Set()
{
}

[bool] Test()
{
return $false
}

[SystemctlService] Get()
{

return [SystemctlService]::GetAll() | Where-Object {$_.Unit -eq $this.Unit }
}

static [SystemctlService[]] Export()
{
return [SystemctlService]::GetAll()
}

static [SystemctlService[]] GetAll()
{
$out = systemctl -l --type service --all
$resultList = [List[SystemctlService]]::new()
$out | select-object -skip 1 | select-object -skiplast 7 | %{
$arr = $_.split(" ", [System.StringSplitOptions]::RemoveEmptyEntries)

if ($arr[2] -ne 'not-found') {
$obj = New-Object SystemctlService
$obj.Unit = $arr[0]
$obj.Load = $arr[1]
$obj.Active = $arr[2]
$obj.Sub = $arr[3]
$obj.Description = ($arr | select-object -last ($arr.Count - 4)) -join " "

$resultList.Add($obj)
}
}
return $resultList.ToArray()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

@{

# Script module or binary module file associated with this manifest.
RootModule = 'Microsoft.DSC.Experimental.Systemctl.psm1'

# Version number of this module.
ModuleVersion = '0.0.1'

# ID used to uniquely identify this module
GUID = 'b267fa32-e77d-48e6-9248-676cc6f232ab'

# Author of this module
Author = 'Microsoft'

# Company or vendor of this module
CompanyName = 'Microsoft Corporation'

# Copyright statement for this module
Copyright = '(c) Microsoft. All rights reserved.'

# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
FunctionsToExport = @()

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
CmdletsToExport = '*'

# Variables to export from this module
VariablesToExport = @()

# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
AliasesToExport = @()

# DSC resources to export from this module
DscResourcesToExport = 'SystemctlService'

# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
PrivateData = @{
PSData = @{
DscCapabilities = @(
'Get'
'Export'
)
}
}

}

Loading