How to determine if the LCM is running

Tagged: 

This topic contains 3 replies, has 2 voices, and was last updated by Profile photo of Daniel Krebs Daniel Krebs 2 years, 2 months ago.

  • Author
    Posts
  • #19432
    Profile photo of Craig Martin
    Craig Martin
    Member

    Trying to optimize some custom DSC resources by storing some temporary files. In my DSC resources I want to skip generating those files if the LCM is currently processing the configuration.

    Looking at the DSC event log it looks like a job ID is assigned it each run. Wondering if that is available somehow to the DSC resources, or if I should just read the event log to find it.

  • #19433
    Profile photo of Daniel Krebs
    Daniel Krebs
    Participant

    Hi Craig,

    At the moment what you're asking does not make sense (at least not to me). Please give us examples of what your/the custom DSC resources are doing to get a better understanding.

    Thanks
    Daniel

  • #19437
    Profile photo of Craig Martin
    Craig Martin
    Member

    Sure thing, thanks for asking.

    I am going to use DSC for configuration management of something called the Forefront Identity Manager Synchronization Service (FIM Sync for short). To do so I need to create some custom DSC resources that will read the FIM sync configuration. The only supported way to read the FIM Sync configuration is to export it to a bunch of XML files. The challenge is that I don't want to export these files each time my custom DSC resources run. A typical FIM Sync configuration could have hundreds of configuration items, so it would suck to dump those files hundreds of times each time the LCM ran.

    What I'd like to do is:
    1. Export the FIM Sync configuration when the LCM starts
    2. Each custom DSC resource reads the configuration from the files
    3. Delete the FIM Sync configuration files when the LCM finishes

    As a workaround I'm thinking about just dumping the configuration on a schedule, then have the DSC resources read those files.

    -Craig

  • #19445
    Profile photo of Daniel Krebs
    Daniel Krebs
    Participant

    Thanks for the details. I think want you're looking forward can be achieved without an additional scheduled task. The LCM gets triggered by a scheduled tasks call Consistency.

    You can use the Script resource to dump the XML configuration or create your own (hopefully soon Community) resource to achieve the same.

    Example configuration script:

    Configuration FIM
    {
        # 1. Export the FIM Sync configuration when the LCM runs your configuration
        # You could replace the Script resource with your own export resource.
        Script 'ExportXML'
        {
            TestScript = 
            {
                return $false # Always return $false to tell the LCM to execute the SetScript
            }
            SetScript = 
            { 
                # Export the FIM configuration
            }
            GetScript = 
            {
                return @{
                    GetScript = $GetScript
                    SetScript = $SetScript
                    TestScript = $TestScript
                    Credential = $Credential
                    Result = (& $TestScript)
                }
            }
        }
    
        # 2. Each custom DSC resource reads the configuration from the files
        YourCustomResource 'Configuration1'
        {
            DependsOn = '[Script]ExportXML'
        }
        YourCustomResource 'Configuration2'
        {
            DependsOn = '[Script]ExportXML'
        }
    
        # 3. Delete the FIM Sync configuration files when the LCM finishes
        # If you export your XML into C:\ProgramData\Microsoft\Windows\PowerShell\Configuration\BuiltinProvCache the LCM should clean up the XML before the next run.
        # Check out the source code for xPackage resource for ideas.
    }
    

    #Daniel

You must be logged in to reply to this topic.