Skip to content

Commit 36313a5

Browse files
author
Andrew
committed
Linux Service Module
1 parent c0b2590 commit 36313a5

File tree

2 files changed

+126
-0
lines changed

2 files changed

+126
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
@{
5+
6+
# Script module or binary module file associated with this manifest.
7+
RootModule = 'Microsoft.DSC.Experimental.psm1'
8+
9+
# Version number of this module.
10+
ModuleVersion = '0.0.1'
11+
12+
# ID used to uniquely identify this module
13+
GUID = 'b267fa32-e77d-48e6-9248-676cc6f232ab'
14+
15+
# Author of this module
16+
Author = 'Microsoft'
17+
18+
# Company or vendor of this module
19+
CompanyName = 'Microsoft Corporation'
20+
21+
# Copyright statement for this module
22+
Copyright = '(c) Microsoft. All rights reserved.'
23+
24+
# 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.
25+
FunctionsToExport = @()
26+
27+
# 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.
28+
CmdletsToExport = '*'
29+
30+
# Variables to export from this module
31+
VariablesToExport = @()
32+
33+
# 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.
34+
AliasesToExport = @()
35+
36+
# DSC resources to export from this module
37+
DscResourcesToExport = 'Service'
38+
39+
# 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.
40+
PrivateData = @{
41+
PSData = @{
42+
DscCapabilities = @(
43+
'Get'
44+
'Export'
45+
)
46+
}
47+
}
48+
49+
}
50+
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
using namespace System.Collections.Generic
5+
6+
[DscResource()]
7+
class Service
8+
{
9+
[DscProperty(Key)]
10+
[string] $Unit
11+
12+
[DscProperty()]
13+
[string] $Load
14+
15+
[DscProperty()]
16+
[string] $Active
17+
18+
[DscProperty()]
19+
[string] $Sub
20+
21+
[DscProperty()]
22+
[string] $Description
23+
24+
[void] Set()
25+
{
26+
}
27+
28+
[bool] Test()
29+
{
30+
return $false
31+
}
32+
33+
[Service] Get()
34+
{
35+
36+
return [Service]::GetServices() | ? {$_.Unit -eq $this.Unit }
37+
}
38+
39+
static [Service[]] Export()
40+
{
41+
$resultList = [List[Service]]::new()
42+
$svcs = [Service]::GetServices()
43+
$svcs | %{
44+
$obj = New-Object Service
45+
$obj.Unit = $_.Unit
46+
$obj.Load = $_.Load
47+
$obj.Active = $_.Active
48+
$obj.Sub = $_.Sub
49+
$obj.Description = $_.Description
50+
51+
$resultList.Add($obj)
52+
}
53+
54+
return $resultList.ToArray()
55+
}
56+
57+
static [pscustomobject[]] GetServices()
58+
{
59+
$out = systemctl -l --type service --all
60+
$resultList = [List[pscustomobject]]::new()
61+
$out | select-object -skip 1 | select-object -skiplast 7 | %{
62+
$arr = $_.split(" ", [System.StringSplitOptions]::RemoveEmptyEntries)
63+
64+
$a = [pscustomobject]@{
65+
Unit = $arr[0]
66+
Load = $arr[1]
67+
Active = $arr[2]
68+
Sub = $arr[3]
69+
Description = ($arr | select-object -last ($arr.Count - 4)) -join " "
70+
}
71+
72+
if ($a.active -ne 'not-found') { $resultList.Add($a)}
73+
}
74+
return $resultList.ToArray()
75+
}
76+
}

0 commit comments

Comments
 (0)