8 Replies Latest reply on Oct 3, 2012 8:13 AM by Lazar NameToUpdate

    Update Server Property after Job Finishes

    Robert Stinnett

      Greetings all,

       

      Slowly but surely learning more and more about BL and how things work.

       

      I have a package that installs Patrol (a Linux package and a Windows package).  I've also created a custom server property called PATROL_INSTALLED which is a boolean.  By default it is "false".

       

      I want to set this to "true" after the software (job) finishes.  I know I have to use the blcli command to set the property.

       

      My question is -- is there any way to incorporate this directly into the package?  Right now I'm creating a NSH script (one line) and importing it into the Depot, creating a NSH job, then creating a batch file to run my package installer and then call the NSH job.  Seems like a whole lot of work for something that shouldn't be this difficult to set a property!

       

      Any tips?

       

      Thanks,

      Robert

        • 1. Re: Update Server Property after Job Finishes

          Hello Robert,

           

          You may use "post command" feature in bldeploy job to run the command.

           

          The Pre/Post Commands dialog box lets you execute commands on a target

          directory before and after a package is deployed to a server. It also lets you execute

          commands on a target directory before a deployment is undone and after it is undone.

          A pre- or postcommand can consist of a number of commands that can be executed

          by the native operating system of a remote host. After you define pre- and

          postcommands, they are saved to the file server as script files. When a job runs, it

          uses the

          nexec -e

          command to execute the pre- and postcommands. When you

          execute a precommand, the target directory is first created (if it does not already

          exist) and then the precommand is executed in the target directory. Postcommands

          are executed in the target directory.

          You can create pre- and postcommands by entering commands in the text box or

          importing text from a file on any managed server. here is screen shot for more details.

          .post_command.JPG

           

          Thanks,

           

          ~Sujit..

          • 2. Re: Update Server Property after Job Finishes

            Sujit,

             

            It will not work, because the blcli commands should be run from the appserver (or client that has nsh and able to authenticate to the appserver). The pre and post commands are executed on the target itself, so the blcli will fail.

            Plus, this is set at the Job level, and I think Robert is looking to incorporate this into the BLPackage.

             

            Robert,

             

            Unfortunately at this time, I believe you have the best method to do this.. I can think of another one, but it will also involve a lot of overhaul, so I'd just stick with yours.

             

            Lazar

            • 3. Re: Update Server Property after Job Finishes
              Bill Robinson

              robert - what are you going to do w/ this property?

              • 4. Re: Update Server Property after Job Finishes

                he just wants to set it to "true" after software is installed. He probably has another Smart Group in Console where he filters by this property to see what servers have this software installed.... standard use case.

                • 5. Re: Update Server Property after Job Finishes
                  Robert Stinnett

                  Lazar is right, we are using this smart group to determine where we still need to push the software too.

                  • 6. Re: Update Server Property after Job Finishes

                    Robert,

                     

                    Here's one way of doing this by only dealing with the NSH Script Job and having the Deploy Job run in the background.

                     

                    Create NSH Type 2 script with one parameter:
                    Name - Hosts
                    Default Value - %h

                     

                    Here is the script:

                     

                    Targets=$1
                    TargetList=`echo "$Targets" | sed 's/ /,/g'`

                     

                    # get already existing deploy job info

                    JobFolder="/DeployJobFolder"
                    JobName="DeployJobName"

                    blcli_execute DeployJob getDBKeyByGroupAndName "$JobFolder" "$JobName"
                    blcli_storeenv JobKey

                     

                    # modify the target list of this deploy job with the list of targets set for the nsh script job
                    blcli_execute Job clearTargetServers $JobKey
                    blcli_storeenv JobKey
                    blcli_execute Job clearTargetGroups $JobKey
                    blcli_storeenv JobKey
                    blcli_execute Job addTargetServers $JobKey "$TargetList"
                    blcli_storeenv JobKey

                     

                    # execute deploy job (aka: install the software on your targets)

                    blcli_execute DeployJob executeJobAndWait $JobKey
                    blcli_storeenv JobRunKey # in case you want to store the runKey, but not needed for this purpose

                     

                    # test each target individually if software is installed, and if yes, then update its server property

                    for Target in $Targets
                    do
                         nexec $Target [CHECK IF SOFTWARE INSTALLED]
                         if [ YES ]; then
                              blcli_execute Server setPropertyValueByName $Target PATROL_INSTALLED True
                         fi
                    done

                     

                    Lazar

                    1 of 1 people found this helpful
                    • 7. Re: Update Server Property after Job Finishes
                      Bill Robinson

                      another way entirely would be to create your smart group based on component existence.  create a discovery job that discovers components based on the existence of your software and then create a server smart group for servers that lack that component.

                       

                      run your install, run a discover job.

                      1 of 1 people found this helpful
                      • 8. Re: Update Server Property after Job Finishes

                        Robert, did you find any of this useful? What process did you end up implementing?