1 2 Previous Next 18 Replies Latest reply on Feb 4, 2015 8:05 AM by Bill Robinson

    NSHScriptJob queue

    Mohammed Ali Khan



      I have a question regarding NSH Script Jobs which I am running on BL8.3 (Bladelogic Server Automation console).


      -> I have a simple NSH Script in my depot folder

      -> I created a NSHScriptJob to execute the NSH script

      -> When I execute the job, it works

      -> However, when the job is running and I try to execute it again, the execution fails with message ("Already Running").

      -> The job may or may not execute against the same target so the option "Number of Targets to Process in Parallel" can to limited to 1 (because we want to queue).


      Can you please help me setup this job so:


      -> I run this job against target 'A'.

      -> Whenever the job is still running and I try to execute this job again, instead of failing the new execution, it should queue it until the current run has completed (regardless of the target server being same or not).


      Thank you very much in advance.

        • 1. Re: NSHScriptJob queue
          Bill Robinson

          when you execute it are you running it or using 'execute against' ?

          • 2. Re: NSHScriptJob queue
            Mohammed Ali Khan

            Hi Bill,


            I am using the option "execute against"

            • 3. Re: NSHScriptJob queue
              Monoj Padhy

              Same job can't be triggered twice unless your previous job run completes. So what you are looking for is may not be feasible.


              Why are you doing so ? What exactly are you trying to achieve here ?


              Bill- In either case I think its not going allow to begin a new execution unless previous job run completes.

              • 4. Re: NSHScriptJob queue
                Mohammed Ali Khan

                Hi Monoj,


                I have a restriction with this NSH Script when it executes,


                -> The script may be invoked multiple times by the user (imagine multiple execution requests at same time)

                -> However, the script may only run serially (i.e. any requests to execute the script if it is already running should be queued until the active execution has completed)




                Running the NSH script as a NSHScriptJob is not a 'must' for me. The reason I am using NSHScriptJob to execute this script is because it is my understanding that this is the way to execute a NSH script. I am mentioning this because if there is another way of executing this NSH Script which would allow for queuing (as mentioned), I would be willing to give it a shot.


                Thanks in advance.

                • 5. Re: NSHScriptJob queue
                  Rajeev Gupta

                  You can create a new NSH Script job if its runing already. The one which is already running wont run until it completes the first run.

                  • 6. Re: NSHScriptJob queue
                    Rajeev Gupta

                    If you want a sequential run, use a batch job..

                    • 7. Re: NSHScriptJob queue
                      Bill Robinson

                      What ‘type’ of nsh script is it ?  runscript?  ‘run once’, etc?  i thought for type 1 (runscript) that would work.  maybe you can create an execution task w/ the different targets.

                      • 8. Re: NSHScriptJob queue
                        Bill Robinson

                        Have you tried execution tasks here ?

                        • 9. Re: NSHScriptJob queue
                          Monoj Padhy

                          when you say multiple execution requests by different users..how many users are there who has access to this script ?


                          you can create a different job referring to the same script either w/ same target servers or different and then you should be good to execute the script as your wish but waiting in queue until 1st one completes is looks difficult to handle.


                          But may be feasible using some tricky scripting. Not sure how far my idea would be feasible to implement...looks difficult

                          where the script will checks the status of your scripting job. Put some wait time.

                          once the previous job run is over add the list of target servers to your job and then  trigger the job.


                          Another option would be creating a execution task w/ whatever target servers you wish to run against.

                          • 10. Re: NSHScriptJob queue
                            Mohammed Ali Khan

                            Just to give an idea,


                            the NSH script is very basic:


                            sleep 30





                            Hi Rajeev,


                            -> I tried creating two NSHScriptJobs from the same NSH script and execute them at the same time (against same target) -- it runs both jobs to success but doesn't queue the second job as I want to.


                            -> How do you go about creating a batch job for NSH Scripts? I looked into the user guide and it seems that Batch Job is created by 'patching job'?? (when I right-click the NSH script in depot -- The only job option I see is for NSHScriptJob).


                            Hi Bill,


                            -> Yes it is a 'runscript'.

                            -> I tried execution tasks but perhaps its my misunderstanding which isn't yielding the results I desire: when I execute the same execution task while it is running, the 2nd execution goes straight to failure (without queuing). When I create two execution tasks and run them, they both run to success (no queuing either).


                            Hi Monoj,


                            -> I would be willing to create different jobs for each execution request however when I tried this, it runs both jobs to success (against same target) and does not go into queue.


                            -> I agree the queuing mechanism can be perhaps coded at a higher level above BSA (I am calling BSA from my webservice and could place the queue mechanism there) but as you mentioned, it would be undesirable especially if BSA can handle this.

                            • 11. Re: NSHScriptJob queue
                              Bill Robinson

                              So i’m unclear what you are trying to accomplish here, since i think the multiple ETs seems to work.  why do you want to queue up the runs of the job ?

                              • 12. Re: NSHScriptJob queue
                                Mohammed Ali Khan

                                Hi Bill,


                                My use case is:


                                -> Our 'code promote system' is a mix of Ruby code and NSH code (the actual logic is written in NSH for legacy reasons).


                                -> Our business rule that leads to this queuing requirement is: Each application may promote only 'one' code package at a time (regardless whether the target is same or not).


                                When I try multiple ETs against the same script + target server, there seems to be no queuing happening -- they simply run to completion in parallel.


                                Bill, maybe my approach is not right for this solution so please, by all means feel free to offer an alternative solution.


                                Thanks for the help guys!!

                                • 13. Re: NSHScriptJob queue
                                  Yanick Girouard

                                  If your NSH Script is a type 2 NSH Script Job (which runs sequentially using a manual loop), and you want parallelism, you need to do something like this to be able to run multiple processes in parallel:


                                  parallelize () {
                                      while [ $# -gt 0 ] ; do
                                          jobcnt=(`jobs -p`)
                                          if [ ${#jobcnt[@]} -lt $maxjobs ] ; then
                                              your_command_here >$$.$servername.out &
                                  parallelize $SERVERS
                                  # To display the output per server, loop through all .out files
                                  for s in $SERVERS; do
                                      cat $$.$s.out
                                      rm -f $$.$s.out
                                  • 14. Re: NSHScriptJob queue
                                    Bill Robinson

                                    ?i'm not sure if that will work...



                                    i get what you are trying to do though - you want bsa to basically throttle and do something like "take requests for job X, if the job is running, get in queue and run when the existing run completes"  requests could come at any time.



                                    right now bsa doesn't work like this.  jobs don't queue up like this.  can you do the queuing on the CI server or whatever ?  so implement some kind of locking and queing there where the request isn't sent to bsa until the current request is done ?



                                    you can also create an 'idea' for this kind of behaviour - imo this is what should happen by default - just wait for the current run to complete and then start the next one.  the whole 'job is already running' seems kind of dumb if it could just queue up.

                                    1 2 Previous Next