Ryan Irujo

  • Tom,

    It sounds like you are attempting to run the omiserver with a user that either doesn’t have sudo rights or isn’t root.

    I would make sure that you are logged in either as root or are running the command to configure and start the omiserver with sudo rights:

    sudo chmod 755 /etc/init.d/omiserver ; chkconfig omiserver on ; service o…[Read more]

  • ThumbnailIn last week’s post, Day 92: Deploying SQL Server 2012 using Chef – Part 3,we modified our SQL Server 2012 Recipe to include a SQL Custom Configuration File. Additionally, we used two accounts for the SQL Services […]

  • ThumbnailIn last week’s post, Day 87: Deploying SQL Server 2012 using Chef – Part 2, we demonstrated how to utilize Chef Data Bags when Deploying SQL Server 2012 Standard.. In that post, we demonstrated how to store […]

  • In last week’s post, Day 82: Deploying SQL Server 2012 using Chef – Part 1, we demonstrated how to deploy SQL Server 2012 Standard using Chef. In that post, you may be have noticed that we used variables within […]

  • In this week’s post, we are going to build on the previous Windows based Chef Articles and demonstrate how you can deploy a standard configuration of SQL Server 2012 in your environment using […]

  • In last week’s post, Day 72: Deploying the SCCM 2012 R2 Client to Linux using Chef, we demonstrated a recipe for deploying the SCCM 2012 R2 Client to a Linux Host running Ubuntu Server 12.04. In this week’s post, […]

  • ThumbnailIf you have been following along with the Chef related articles, you may remember that the last Chef post was on Day 62, Deploying your Windows Recipe from your Chef Server. Today, we will be going over a Chef […]

  • ThumbnailThis week, I will be discussing a Script that I wrote to check DNS Resolution and the availability of Network Ports on multiple hosts. (More Chef related Articles will be coming in future installments).

    If you […]

  • ThumbnailIn last week’s post, Chef: A Simple Recipe and Cookbook for Windows, we demonstrated how to create a simple Chef Cookbook with a functional recipe for deploying the Web-Server and Web-Mgmt-Tools Features; along […]

  • In last week’s post, Bootstrapping the Chef Client onto a Windows Host, we demonstrated how to deploy the Chef Client onto Windows Server 2012 R2. This week, we are going to get started with a sample Chef recipe […]

  • ThumbnailIn last week’s post, Bootstrapping the Chef Client onto a Linux Host, we demonstrated how to deploy the Chef Client onto Ubuntu 12.04. This week, we’ll be demonstrating the same process on a Windows Server 2012 R2 […]

  • ThumbnailIn last week’s post, Setting up a Chef Workstation, we demonstrated how to setup a Chef Workstation on Ubuntu 12.04 so that you can manage both your Chef Server and the Hosts that are being managed by […]

  • In last week’s post, Getting Started with Chef, we demonstrated how to setup a Chef Server, this week we’ll go over how to setup a Chef Workstation on Ubuntu 12.04.

    Any queries or changes to your Chef […]

  • My previous posts have focused on how to use PowerShell DSC for Linux. Going forward, I will be posting about how to deploy and use the configuration management tool called Chef. The end goal of this series of […]

  • Following up to last week’s article, Day 27: Managing Linux Users and Groups using PowerShell DSC, this week we’ll be demonstrating how to manage multiple resources in Linux using PowerShell DSC. In This week’s post is two examples, one for Ubuntu and one for CentOS, showing what a configuration can look like that is managing multiple items on a single host.

     

     
    Sample Script for managing Multiple Resources in CentOS 6.2
    Below is a sample Script that will do the following:
    Ensures that the scom-svc-centos user is present.
    Ensures that the scom-svc-users group is present.
    Ensures that the root and scom-svc-centos users are members of the scom-svc-users group.
    Ensures that the crond service is running.
    Resets the password of the scom-svc-centos user account.
    It should go without saying that storing credentials in clear text for Production purposes is a really bad idea; but just in case, the password here is in clear text for demonstration purposes only!
    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 CentOS Host.

    ################################################################################

    Clear-Host

    $Cred = Get-Credential -Username:”root” -Message:”Enter root user password for the Linux Host(s).”

    $Opt = New-CimSessionOption -UseSSL:$True -SkipCACheck:$True -SkipCNCheck:$True -SkipRevocationCheck:$True

    $LinuxServer = New-CimSession -Credential:$Cred -ComputerName:<COMPUTERNAME> -Port:5986 -Authentication:Basic -SessionOption:$Opt

    Configuration Multiple_Resources_CentOS
    {
    Import-DSCResource -Module nx
    Node $LinuxServer.ComputerName
    {
    nxUser SCOM_Service_Account
    {
    Username = “scom-svc-centos”
    Ensure = “Present”
    FullName = “SCOM Test Service Account – CentOS”
    Description = “SCOM Test Service Account for all CentOS Hosts”
    }

    nxGroup SCOM_Service_Users
    {
    GroupName = “scom-svc-users”
    Ensure = “Present”
    Members = @(“root”,”scom-svc-centos”)
    }

    nxService crond
    {
    Name = “crond”
    Controller = “init”
    Enabled = “True”
    State = “Running”
    }

    nxScript PasswordReset
    {
    User = “root”
    Group = “root”
    SetScript = {#!/usr/bin/expect -f
    #
    set username “scom-svc-centos”
    set newpassword “P@ssw0rd”

    spawn passwd $username
    expect “New password:”
    send “$newpasswordr”
    expect “Retype new password:”
    send “$newpasswordr”
    expect eof}
    TestScript = {}
    GetScript = {}
    }
    }
    }

    Write-Host “Multiple_Resources_CentOS – Configuration Loaded”

    Multiple_Resources_CentOS -OutputPath C:LinuxConfigs | Out-Null

    Start-DscConfiguration -CimSession:$LinuxServer -Path:”C:LinuxConfigs” -Verbose -Wait
    ################################################################################
     

     
    Sample Script for managing Multiple Resources in Ubuntu 12.04
    Below is a sample Script that will do the following:
    Ensures that the scom-svc-ubuntu user is present.
    Ensures that the scom-svc-users group is present.
    Ensures that the root and scom-svc-ubuntu users are members of the scom-svc-users group.
    Ensures that the cron service is running.
    Resets the password of the scom-svc-ubuntu user account.
    It should go without saying that storing credentials in clear text for Production purposes is a really bad idea; but just in case, the password here is in clear text for demonstration purposes only!
    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.

    ################################################################################

    Clear-Host

    $Cred = Get-Credential -Username:”root” -Message:”Enter root user password for the Linux Host(s).”

    $Opt = New-CimSessionOption -UseSSL:$True -SkipCACheck:$True -SkipCNCheck:$True -SkipRevocationCheck:$True

    $LinuxServer = New-CimSession -Credential:$Cred -ComputerName:<COMPUTERNAME> -Port:5986 -Authentication:Basic -SessionOption:$Opt

    Configuration Multiple_Resources_Ubuntu
    {
    Import-DSCResource -Module nx
    Node $LinuxServer.ComputerName
    {
    nxUser SCOM_Service_Account
    {
    Username = “scom-svc-ubuntu”
    Ensure = “Present”
    FullName = “SCOM Test Service Account – Ubuntu”
    Description = “SCOM Test Service Account for all Ubuntu Hosts”
    }

    nxGroup SCOM_Service_Users
    {
    GroupName = “scom-svc-users”
    Ensure = “Present”
    Members = @(“root”,”scom-svc-ubuntu”)
    }

    nxService cron
    {
    Name = “cron”
    Controller = “init”
    Enabled = “True”
    State = “Running”
    }

    nxScript PasswordReset
    {
    User = “root”
    Group = “root”
    SetScript = {#!/usr/bin/expect -f
    #
    set username “scom-svc-ubuntu”
    set newpassword “P@ssw0rd”

    spawn passwd $username
    expect “Enter new UNIX password:”
    send “$newpasswordr”
    expect “Retype new UNIX password:”
    send “$newpasswordr”
    expect eof}
    TestScript = {}
    GetScript = {}
    }
    }
    }

    Write-Host “Multiple_Resources_Ubuntu – Configuration Loaded”

    Multiple_Resources_Ubuntu -OutputPath C:LinuxConfigs | Out-Null

    Start-DscConfiguration -CimSession:$LinuxServer -Path:”C:LinuxConfigs” -Verbose -Wait
    ################################################################################
     
     Conclusion
    This week’s post has demonstrated how to manage Multiple Resource in Linux using PowerShell DSC. Hopefully, this has given you some ideas on how you can template resource management for your Linux Environment.

    Previous Installments
    100 Days of DevOps with PowerShell
     

     

     

     

     

     

     

     

     

     

     

     

  • Following up to last week’s article, Day 22: Managing Linux Users and Groups using PowerShell DSC, this week we’ll be demonstrating how to manage Linux Scripts in Ubuntu and CentOS using PowerShell DSC. Included […]

  • As I mentioned in last week’s article, Day 17: Managing Linux Files using PowerShell DSC, this week we’ll be discussing how to manage Linux Users and Groups in Ubuntu and CentOS using PowerShell DSC.
    Introduction […]

  • Following in the same vein as last week’s article: Day 12: Managing Linux Services using PowerShell DSC, this week we’ll be discussing how to manage Linux Files in both Ubuntu and CentOS using PowerShell DSC.
    Introduction to the MSFT_nxFileResource Class
    By default, the MOF file, MSFT_nxFileResource.schema.mof, is installed in the following path when you install the nx-PSModule:

    C:WindowsSystem32WindowsPowerShellv1.0ModulesnxDSCResourcesMSFT_nxFileResource

    The contents of the MOF file are below:
    [ClassVersion(“1.0.0”), Description(“The configuration provider for files and directories.”), FriendlyName(“nxFile”)]
    class MSFT_nxFileResource:OMI_BaseResource
    {
    [Key] string DestinationPath;
    [Write] string SourcePath;
    [Write, ValueMap{“present”, “absent”}] string Ensure;
    [Write, ValueMap{“file”, “directory”, “link”}] string Type;
    [Write] string Contents;
    [Write, ValueMap{“md5”, “md5lite”, “mtime”, “ctime”, “none”}] string Checksum;
    [Write, ValueMap{“true”, “false”}] string Recurse;
    [Write, ValueMap{“true”, “false”, “yes”, “no”}] string Force;
    [Write, ValueMap{“follow”, “manage”}] string Links;
    [Write] string Group;
    [Write] string Mode;
    [Write] string Owner;
    [Read] datetime CreatedDate;
    [Read] datetime ModifiedDate;
    };

    Below is a quick breakdown of the most important aspects of the file:

    — We need to provide the path where the File or Directory will reside

    — We need to provide the Source Path of the File (this is only required if the Contents Value isn’t used)

    — We need to provide the Contents of the File (this has some limitations which we’ll cover.)

    — We need to provide the Group the file will belong too.

    — We need to provide the Mode (Permissions) of the file in octal or symbolic notation

    — We need to provide the owner of the file.

     
    Limitations of the Contents Field
    As you may have noticed earlier, the Contents field is interpreted as a String as stated in the MOF File. In reality, certain special characters are interpreted by this field if you include them and do not escape them using the grave-accent (`).

    While this might not seem like a major issue, the majority of configuration files used by Linux based applications will more than likely use one or more of the following special characters:
    ! # $ % ^ & ( ) { } [ ] #

    An example of where this can become a real problem, is in regards to the standard sshd script in the /etc/init.d/ directory in CentOS.

    Below are the first 55 lines of the Script:
    #!/bin/bash
    #
    # sshd Start up the OpenSSH server daemon
    #
    # chkconfig: 2345 55 25
    # description: SSH is a protocol for secure remote shell access.
    # This service starts up the OpenSSH server daemon.
    #
    # processname: sshd
    # config: /etc/ssh/ssh_host_key
    # config: /etc/ssh/ssh_host_key.pub
    # config: /etc/ssh/ssh_random_seed
    # config: /etc/ssh/sshd_config
    # pidfile: /var/run/sshd.pid

    ### BEGIN INIT INFO
    # Provides: sshd
    # Required-Start:
    # Required-Stop:
    # Should-Start:
    # Should-Stop:
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Short-Description: Start up the OpenSSH server daemon
    # Description: SSH is a protocol for secure remote shell access.
    # This service starts up the OpenSSH server daemon.
    ### END INIT INFO

    # source function library
    . /etc/rc.d/init.d/functions

    # pull in sysconfig settings
    [ -f /etc/sysconfig/sshd ] && . /etc/sysconfig/sshd

    RETVAL=0
    prog=”sshd”
    lockfile=/var/lock/subsys/

    # Some functions to make the below more readable
    KEYGEN=/usr/bin/ssh-keygen
    SSHD=/usr/sbin/sshd
    RSA1_KEY=/etc/ssh/ssh_host_key
    RSA_KEY=/etc/ssh/ssh_host_rsa_key
    DSA_KEY=/etc/ssh/ssh_host_dsa_key
    PID_FILE=/var/run/sshd.pid

    runlevel=$(set — $(runlevel); eval “echo $$#” )

    fips_enabled() {
    if [ -r /proc/sys/crypto/fips_enabled ]; then
    cat /proc/sys/crypto/fips_enabled
    else
    echo 0
    fi
    }

     

    In order to get these 55 lines to show up correctly when pushing out the configuration file to the CentOS Host, the following lines have to have one or more characters escaped:
    prog=`”sshd`”
    runlevel=`$`(set — `$`(runlevel`); eval `”echo “$`$`#`” `)

    Just in those 2 Lines of Code, I had to escape 14 characters in order for the first 55 lines of the sshd script to be successfully pushed out to the CentOS Host. In order to give you the magnitude of the scope of work that may be required, the entire script is 234 lines.

    The Final Resource Definition in PowerShell is shown below. Something else that should be noted here, I had to copy and paste the code directly before escaping characters so that I would not mess up the formatting of the script. If you try and clean up the way the code looks in the PowerShell Configuration, you will mess up the formatting when it is on the Linux host and potentially break the script.
    nxFile Sample_File
    {
    Ensure = “Present”
    Type = “File”
    Contents = “#!/bin/bash
    #
    # sshd Start up the OpenSSH server daemon
    #
    # chkconfig: 2345 55 25
    # description: SSH is a protocol for secure remote shell access.
    # This service starts up the OpenSSH server daemon.
    #
    # processname: sshd
    # config: /etc/ssh/ssh_host_key
    # config: /etc/ssh/ssh_host_key.pub
    # config: /etc/ssh/ssh_random_seed
    # config: /etc/ssh/sshd_config
    # pidfile: /var/run/sshd.pid

    ### BEGIN INIT INFO
    # Provides: sshd
    # Required-Start: $local_fs $network $syslog
    # Required-Stop: $local_fs $syslog
    # Should-Start: $syslog
    # Should-Stop: $network $syslog
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Short-Description: Start up the OpenSSH server daemon
    # Description: SSH is a protocol for secure remote shell access.
    # This service starts up the OpenSSH server daemon.
    ### END INIT INFO

    # source function library
    . /etc/rc.d/init.d/functions

    # pull in sysconfig settings
    [ -f /etc/sysconfig/sshd ] && . /etc/sysconfig/sshd

    RETVAL=0
    prog=`”sshd`”
    lockfile=/var/lock/subsys/$prog

    # Some functions to make the below more readable
    KEYGEN=/usr/bin/ssh-keygen
    SSHD=/usr/sbin/sshd
    RSA1_KEY=/etc/ssh/ssh_host_key
    RSA_KEY=/etc/ssh/ssh_host_rsa_key
    DSA_KEY=/etc/ssh/ssh_host_dsa_key
    PID_FILE=/var/run/sshd.pid

    runlevel=`$`(set — `$`(runlevel`); eval `”echo “$`$`#`” `)

    fips_enabled() {
    if [ -r /proc/sys/crypto/fips_enabled ]; then
    cat /proc/sys/crypto/fips_enabled
    else
    echo 0
    fi
    }

    DestinationPath = “/tmp/sample_file”
    }

    Using the SourcePath Field
    An alternative to using the Contents Field is to use the SourcePath Field. The upside to utilizing this Field is that you don’t have to worry about escaping characters in your bash scripts or configuration files before adding them to your DSC Configuration. The downside is that you have to provide a path that is local to the Linux Host that you are targeting. As many of you are astute readers, you can immediately understand how this is in many ways self-defeating.

    In order to utilize the SourcePath Field, you must provide the full path to the Directory or File that you want to copy from the Linux Host that you are working with. As of this writing, I have not found a way to utilize the SourcePath to reference a File or Directory that exists on a Network Share, Website or Windows Network Path. An example is given in the Sample Script for managing Linux Files using SourcePath (Ubuntu) section.

     
    Sample Script for Managing Linux Files using SourcePath (Ubuntu)
    Below is a sample Script that copies the ssh script in /etc/init.d to the /tmp directory and names the file ssh_script. Note that this will clobber the file if it already exists in the /tmp directory.

    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.
    #########################################################################################
    Clear-Host

    $Cred = Get-Credential -Username:”root” -Message:”Enter root user password for the Linux Host(s).”

    $Opt = New-CimSessionOption -UseSSL:$True -SkipCACheck:$True -SkipCNCheck:$True -SkipRevocationCheck:$True

    $LinuxServer = New-CimSession -Credential:$Cred -ComputerName:<COMPUTERNAME> -Port:5986 -Authentication:Basic -SessionOption:$Opt

    Configuration Ubuntu_Files
    {
    Import-DSCResource -Module nx
    Node $LinuxServer.ComputerName
    {
    nxFile SSH_Script
    {
    DestinationPath = “/tmp/ssh_script”
    SourcePath = “/etc/init.d/ssh”
    Type = “File”
    Group = “root”
    Mode = “775”
    Owner = “root”
    }
    }
    }

    Write-Host “Ubuntu_Files – Configuration Loaded”

    Ubuntu_Files -OutputPath C:LinuxConfigs | Out-Null

    Start-DscConfiguration –CimSession:$LinuxServer -Path:”C:LinuxConfigs” -Verbose –Wait
    #########################################################################################

     

     
    Sample Script for Managing Linux Files using Contents (CentOS)
    Below is a sample Script that adds the first 55 lines of the sshd script in CentOS to a new file in the /tmp directory called sshd_script_sample. Note that this will clobber the file if it already exists in the /tmp directory.

    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 CentOS Host.
    #########################################################################################
    Clear-Host

    $Cred = Get-Credential -Username:”root” -Message:”Enter root user password for the Linux Host(s).”

    $Opt = New-CimSessionOption -UseSSL:$True -SkipCACheck:$True -SkipCNCheck:$True -SkipRevocationCheck:$True

    $LinuxServer = New-CimSession -Credential:$Cred -ComputerName:<COMPUTERNAME> -Port:5986 -Authentication:Basic -SessionOption:$Opt

    Configuration CentOS_Files
    {
    Import-DSCResource -Module nx
    Node $LinuxServer.ComputerName
    {
    nxFile sshd_script_sample
    {
    Ensure = “Present”
    Type = “File”
    Contents = “#!/bin/bash
    #
    # sshd Start up the OpenSSH server daemon
    #
    # chkconfig: 2345 55 25
    # description: SSH is a protocol for secure remote shell access.
    # This service starts up the OpenSSH server daemon.
    #
    # processname: sshd
    # config: /etc/ssh/ssh_host_key
    # config: /etc/ssh/ssh_host_key.pub
    # config: /etc/ssh/ssh_random_seed
    # config: /etc/ssh/sshd_config
    # pidfile: /var/run/sshd.pid

    ### BEGIN INIT INFO
    # Provides: sshd
    # Required-Start: $local_fs $network $syslog
    # Required-Stop: $local_fs $syslog
    # Should-Start: $syslog
    # Should-Stop: $network $syslog
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Short-Description: Start up the OpenSSH server daemon
    # Description: SSH is a protocol for secure remote shell access.
    # This service starts up the OpenSSH server daemon.
    ### END INIT INFO

    # source function library
    . /etc/rc.d/init.d/functions

    # pull in sysconfig settings
    [ -f /etc/sysconfig/sshd ] && . /etc/sysconfig/sshd

    RETVAL=0
    prog=`”sshd`”
    lockfile=/var/lock/subsys/$prog

    # Some functions to make the below more readable
    KEYGEN=/usr/bin/ssh-keygen
    SSHD=/usr/sbin/sshd
    RSA1_KEY=/etc/ssh/ssh_host_key
    RSA_KEY=/etc/ssh/ssh_host_rsa_key
    DSA_KEY=/etc/ssh/ssh_host_dsa_key
    PID_FILE=/var/run/sshd.pid

    runlevel=`$`(set — `$`(runlevel`); eval `”echo “$`$`#`” `)

    fips_enabled() {
    if [ -r /proc/sys/crypto/fips_enabled ]; then
    cat /proc/sys/crypto/fips_enabled
    else
    echo 0
    fi
    }

    DestinationPath = “/tmp/sshd_script_sample”
    }
    }
    }

    Write-Host “CentOS_Files – Configuration Loaded”

    CentOS_Files -OutputPath C:LinuxConfigs | Out-Null

    Start-DscConfiguration -CimSession:$LinuxServer -Path:”C:LinuxConfigs” –Verbose –Wait
    #########################################################################################

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

    Next week we will be going over how to manage Linux Users and Groups using PowerShell DSC.

     
    Previous Installments

    Announcing the “100 Days of DevOps with PowerShell” Series
    Day 1: Intro to PowerShell DSC and Configuring Your First Pull Server (Aug 1)
    Day 2: How to install DSC Providers for Linux on CentOS 6.2 (Aug 4)
    Day 3: PowerShell and Team Foundation Server 2013 – Getting Started (Aug 5)
    Day 4: Automating Application Installation Using PowerShell Without DSC or OneGet (Aug 6)
    Day 5: Managing Your PowerShell DSC GUIDs in SC 2012 Service Manager (Aug 7)
    Day 6 – Configuring an HTTPS DSC Pull Server (Aug 8)
    Day 7 – How To Install DSC Providers for Linux on Ubuntu 12.04 (Aug 11)
    Day 8 – Using Active Directory to Target Endpoints in PowerShell DSC (Aug 12)
    Day 9 – PowerShell and Team Foundation Server 2013 – Working with Work Items (Aug 13)
    Day 10: Enabling DevOps in Azure VMs (with and without PowerShell DSC) (Aug 14)
    Day 11: Automating Application Installation using OneGet (Aug 15)
    Day 12: Managing Linux Services using PowerShell DSC (Aug 18)
    Day 13: PowerShell and Team Foundation Server 2013 – Using the TFS API (Aug 19)
    Day 14: Finding and Installing Modules and DSC Resources with PowerShellGet (Aug 20)
    Day 15: Working with IE Enhanced Security and User Account Control Settings (Aug 21)
    Day 16: Connecting DevOps and ITIL (and DSC) Through the CMDB (Aug 22)

    • This is a great write-up!   Rather than dealing with escaping all of those characters, why not declare the Contents as a multi-line string literal?  Such as:

      Contents = @’
      #!/bin/bash


      @’

      Alternatively, you could put the contents in a text file and do use Get-Content to read it in to a variable:
      Get-Content “D:ContentsMyFileContents.txt” |out-string

       

  • 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:WindowsSystem32WindowsPowerShellv1.0ModulesnxDSCResourcesMSFT_nxServiceResource

    The contents of the MOF file are below:
    [ClassVersion(“1.0.0”),FriendlyName(“nxService”)]
    class MSFT_nxServiceResource : OMI_BaseResource
    {
    [key] string Name;
    [write,ValueMap{“init”, “upstart”, “systemd”},Values{“init”,”upstart”,”systemd”}] string Controller;
    [write] boolean Enabled;
    [write,ValueMap{“Running”, “Stopped”},Values{“Running”, “Stopped”}] string State;
    [read] boolean IsEnabled;
    [read] string Status;
    [read] string Path;
    };

    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.
    #########################################################################################
    Clear-Host

    $Cred = Get-Credential -Username:”root” -Message:”Enter root user password for the Linux Host(s).”

    $Opt = New-CimSessionOption -UseSSL:$True -SkipCACheck:$True -SkipCNCheck:$True -SkipRevocationCheck:$True

    $LinuxServer = New-CimSession -Credential:$Cred -ComputerName:<COMPUTERNAME> -Port:5986 -Authentication:Basic -SessionOption:$Opt

    Configuration Ubuntu_Services
    {
    Import-DSCResource -Module nx
    Node $LinuxServer.ComputerName
    {
    nxService ssh
    {
    Name = “ssh”
    Controller = “upstart”
    Enabled = “True”
    State = “Running”
    }

    nxService cron
    {
    Name = “cron”
    Controller = “upstart”
    Enabled = “True”
    State = “Running”
    }

    nxService resolvconf
    {
    Name = “resolvconf”
    Controller = “upstart”
    Enabled = “True”
    State = “Running”
    }
    }
    }

    Write-Host “Ubuntu_Services – Configuration Loaded”

    Ubuntu_Services -OutputPath C:LinuxConfigs | Out-Null

    Start-DscConfiguration -CimSession:$LinuxServer -Path:”C:LinuxConfigs” -Verbose –Wait
    #########################################################################################

    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

    Announcing the “100 Days of DevOps with PowerShell” Series
    Day 1: Intro to PowerShell DSC and Configuring Your First Pull Server (Aug 1)
    Day 2: How to install DSC Providers for Linux on CentOS 6.2 (Aug 4)
    Day 3: PowerShell and Team Foundation Server 2013 – Getting Started (Aug 5)
    Day 4: Automating Application Installation Using PowerShell Without DSC or OneGet (Aug 6)
    Day 5: Managing Your PowerShell DSC GUIDs in SC 2012 Service Manager (Aug 7)
    Day 6 – Configuring an HTTPS DSC Pull Server (Aug 8)
    Day 7 – How To Install DSC Providers for Linux on Ubuntu 12.04 (Aug 11)
    Day 8 – Using Active Directory to Target Endpoints in PowerShell DSC (Aug 12)
    Day 9 – PowerShell and Team Foundation Server 2013 – Working with Work Items (Aug 13)
    Day 10: Enabling DevOps in Azure VMs (with and without PowerShell DSC) (Aug 14)
    Day 11: Automating Application Installation using OneGet (Aug 15)

  •  

    For those of you that read last weeks article, Day 2: How to install DSC Providers for Linux on CentOS 6.2, this post may seem a bit redundant as it details the exact same steps demonstrated last week, except […]

  • Load More