Day 12: Managing Linux Services using PowerShell DSC

If you have not already read last weeks article, Day 7 – How To Install DSC Providers for Linux on Ubuntu 12.04, I would recommend doing so before reading on. Today’s article will cover the basics of managing Linux Services using PowerShell DSC in Ubuntu 12.04. In case you feel that Red Hat is being left out, please make sure to read all the way to the end of the article under Additional Notes.

Introduction to  the MSFT_nxServiceResource Class

By default, the MOF file, MSFT_nxServiceResource.schema.mof, is installed in the following path when you install the nx-PSModule:

C:\Windows\System32\WindowsPowerShell\v1.0\Modules\nx\DSCResources\MSFT_nxServiceResource

The contents of the MOF file are below:

Below is a quick breakdown of what’s important from the items in the MOF File:

We need to provide the name of the service we are working with

We need to provide whether the service is controlled by init, upstart, or systemd

We need to provide if the service should either be enabled with a value of True or False

We need to provide a State value of either Running or Stopped

Sample PowerShell DSC Configuration Script for managing Linux Services

Below is a sample Script that checks to see if ssh, cron and resolvconf are all currently running on Ubuntu 12.04. If they are not found to be running, they are automatically started.

To use this script, first create the following directory on your DSC Scripting Host: C:\LinuxConfigs. Next, replace the value <COMPUTERNAME> in the $LinuxServer variable next to the -ComputerName: switch, with the name of your Ubuntu Host.

Additional Notes

When creating/modifying your scripts, make sure to take into account that different flavors of Linux may have a slightly different name for a service. For example, in Ubuntu 12.04, SSH is run as a service under the name ssh. In CentOS 6.2, the same service is run under the name sshd.

Powershell DSC for Linux – Resource References

 Conclusion

I hope this article clarifies how to configure and manage Linux Services in Ubuntu and CentOS using PowerShell DSC.

Next week we will be going over how to manage Linux Files using PowerShell DSC.

Previous Installments

One thought on “Day 12: Managing Linux Services using PowerShell DSC

  1. Profile photo of Tom Gerald

    Gents, you are really killing it with this series. The clear, concise explanations really set this series apart from other work I have seen on PowerShell DSC.

Leave a Reply