setsite in tcl

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf setsite in tcl

  • Creator
    Topic
  • #54573
    Todd Horst
    Participant

      Can you setsite in tcl, without using the exec command.

      If i use exec, once it completes, Im back to the site i started off in.

      This is in the context of a tcl script running at the system level, and not inside an interface

      Thanks

    Viewing 19 reply threads
    • Author
      Replies
      • #82054
        Keith McLeod
        Participant

          Not sure if this will work for you.

          hcisetenv -site

          I ran this from a hcitcl prompt.

        • #82055
          Jeff Dinsmore
          Participant

            I banged my head against this one for a while…

            The solution I settled on is to reset env variables in the Tcl environment.

            Here’s a proc to do that.  It calls Cloverleaf’s hcisetenv (a perl script), then uses the return from that to set environment variables in Tcl.

            It’s not the most elegant, but seems to work well enough.

            Code:


            namespace eval cloverUtils {

            }

            proc cloverUtils::setSite { site } {

            global env

            set envSet [exec [file join $env(HCIROOT) bin hcisetenv] -site $site]

            for { set i 0 } { $i < [llength $envSet] } { incr i } {
            switch -exact — [lindex $envSet $i] {
            set {
            set n [expr $i + 1]
            set v [expr $i + 2]
            set env([lindex $envSet $n]) [regsub -all {'} [lindex $envSet $v] ""]
            incr i 2
            }
            clear {
            incr i
            }
            }
            }

             return 1

            }

            Jeff Dinsmore
            Chesapeake Regional Healthcare

          • #82056
            David Barr
            Participant

              You can also do something like this:

              Code:

              set site test_adt
              global env
              catch { exec $::HciRoot/sbin/hcisetenv -site tcl $site } vars
              eval “$vars”

              But this won’t do a few other things that the command line “setsite”  command does like setting HciSite, HciSiteDir, auto_path, etc.

            • #82057
              Jeff Dinsmore
              Participant

                David the issue with your approach is that, while it does set local variables in the Tcl shell you’re running, it doesn’t set environment variables in the Tcl shell.

                That works fine as long as you only want to use the variable values locally, but if you want to exec a command from Tcl in the scope of a site other than the one your Tcl shell started in, you need to change the env() array variables in your current shell.

                Jeff Dinsmore
                Chesapeake Regional Healthcare

              • #82058
                David Barr
                Participant

                  Actually my approach does update the env array.

                • #82059
                  Russ Ross
                  Participant

                    Instead of struggling with changing sites inside TCL, I went to doing it in the K-Shell that wraps around my TCL.

                    Here is a URL to illustrate that approach

                    <a href="https://usspvlclovertch2.infor.com/viewtopic.php?t=6876&#8243; class=”bbcode_url”>https://usspvlclovertch2.infor.com/viewtopic.php?t=6876

                    Russ Ross
                    RussRoss318@gmail.com

                  • #82060
                    Jeff Dinsmore
                    Participant

                      Russ –

                      Todd’s question was about setting site from inside Tcl.

                      I may have missed something, but the post in the link you supplied looks to address only KSH.

                      Jeff Dinsmore
                      Chesapeake Regional Healthcare

                    • #82061
                      Russ Ross
                      Participant

                        You are correct about my URL showing an approach of using KSH instead of TCL to change sites.

                        I was attempting to illustrate another way to approach looping thru sites that worked for me that was less hassle as opposed to doing it in TCL.

                        I wasn’t even sure it was possible to loop thru sites in TCL correctly until msiDetach came along, and by then I already had an apporach of using the KSH site change wrapper.

                        So basically the KSH script changes sites effectively without observed issues or side effects and calls the TCL script(s) that assume the site has already been set when it is called.

                        If staying with TCL 100% is one of your conditions, then my URL posted appoach will not meet that condition.

                        Russ Ross
                        RussRoss318@gmail.com

                      • #82062
                        Jeff Dinsmore
                        Participant

                          David –

                          I’ll be dipped – so it does…  Looks like I worked too hard at that one.

                          I didn’t notice the “tcl” flag – didn’t know it existed.

                          I had not found the option.  It’s not listed in the  usage at the shell level and it’s buried in my CL documentation.

                          So, Todd.  I’d do it David’s way ;0)

                          Jeff Dinsmore
                          Chesapeake Regional Healthcare

                        • #82063
                          Jeff Dinsmore
                          Participant

                            Russ –

                            You’re absolutely right.  If KSH is your starting point, there’s no pressing need to do it all in Tcl – unless you want to.

                            My need – and I’m assuming Todd’s as well – is primarily from within Tcl UPOC/TPS code inside of Cloverleaf.  From there, it’s much cleaner if you can stay in Tcl.

                            Jeff Dinsmore
                            Chesapeake Regional Healthcare

                          • #82064
                            Todd Horst
                            Participant

                              Thanks for everyones reply, and sorry for the late response.

                              Im trying to do something like:

                              Code:

                              global env
                              eval [exec ksh -c “$env(HCIROOT)/sbin/hcisetenv -site tcl site1″]
                              msiAttach
                              msiGetStatSample Thread1
                              msiDetach

                              eval [exec ksh -c “$env(HCIROOT)/sbin/hcisetenv -site tcl site2″]
                              msiAttach
                              msiGetStatSample Thread2
                              msiDetach

                              This will work for the first thread, outputing the stats correctly. However when i try to do the msiAttach on the next site i get the following error:

                              Code:

                              tcl>msiAttach
                              [0:TEST] oilSysSemOpen: ftok failed
                              Sem Name = /NetConfig Project Id : 90
                              [0:TEST] msiGlobalInit: Can’t open guard sem: No such file or directory
                              msiGlobalInit: NetConfig = /NetConfig
                              Error: shared memory attach failed

                              Has anyone run into this before?

                            • #82065
                              Richard Hart
                              Participant

                                Hi Todd.

                                We are on *ix and generally run one script that loops through the Cloverleaf sites and then calls a second script to perform  the action.

                                When the second script has completed its work, the envieronment is dropped until the next call.  The second script can also be called from  the command line.

                                eg

                                cycleAllLog.sh calling

                                 cycleLog.sh

                                cycleAllSmat.sh calling

                                cycleSmat.sh

                                purgeAllSite.sh calling

                                 purgeSite.sh

                              • #82066
                                David Barr
                                Participant

                                  Todd Horst wrote:

                                  This will work for the first thread, outputing the stats correctly. However when i try to do the msiAttach on the next site i get the following error:

                                  Code:

                                  tcl>msiAttach
                                  [0:TEST] oilSysSemOpen: ftok failed
                                  Sem Name = /NetConfig Project Id : 90
                                  [0:TEST] msiGlobalInit: Can’t open guard sem: No such file or directory
                                  msiGlobalInit: NetConfig = /NetConfig
                                  Error: shared memory attach failed

                                  Has anyone run into this before?

                                  It seems like I’ve run into this and I don’t remember what I did to fix it.

                                  If you want to stay 100% tcl, one possible solution is to loop through all of your sites, call “fork” to spawn a child process. The child process could call msiAttach/msiDetach/exit. The parent process could call “wait” to wait for the child process to finish with each site.

                                • #82067
                                  Todd Horst
                                  Participant

                                    i was thinking something along this line… ill give it a go

                                  • #82068
                                    Russ Ross
                                    Participant

                                      Even though my KSH wrapper for changing sites that calls TCL scripts takes care of my needs, this topic of using all TCL became a splinter in my brain.

                                      I tried all kinds of variations inside a single TCL proc to loop thru sites but always ran into trouble when doing the msiAttach past the first site just like the rest of you indicated.

                                      I asked Steve Fraser and he had the same outcome but did make me aware of a built in cloverleaf TCL proc named ChangeSite that looks promising.

                                      Then I started thinking about a TCL wrapper approach since my KSH wrapper approach works and that showed promise as the following proof of concept examples produced the outcome I was looking for.

                                      Naturally I was looking at a small set of outcomes to determine if success was possible, so swim at your own risk.

                                      Here is my /hcitest/russ/test_changing_sites.tcl standalone wrapper script:

                                      Code:

                                      #!/usr/bin/env hcitcl

                                      set siteList [list test_picis test_ris]

                                      #—————————————————————————————————————-
                                      # method 1 proof of concept using built-in Cloverleaf ChangeSite TCL proc that Steve Fraser told me about, thanks
                                      #—————————————————————————————————————-

                                      echo “n########## method 1 proof of concept ##########”
                                      echo [exec showroot]

                                      foreach site $siteList {
                                         ChangeSite $site
                                         echo [exec /hcitest/russ/test_msiTocEntry.tcl]
                                      }

                                      #——————————————————————————————-
                                      # method 2 proof of concept using clovertech example from David Barr to eval “$vars”, thanks
                                      #——————————————————————————————-

                                      echo “n########## method 1 proof of concept ##########”
                                      echo [exec showroot]

                                      foreach site $siteList {
                                         catch { exec $::HciRoot/sbin/hcisetenv -site tcl $site  } vars
                                         eval “$vars”
                                         echo [exec /hcitest/russ/test_msiTocEntry.tcl]
                                      }

                                      echo “n########## Done ##########”
                                      echo “n[exec showroot]n”

                                      Here is the /hcitest/russ/test_msiTocEntry.tcl standalone TCL script:

                                      Code:

                                      #!/usr/bin/env hcitcl

                                      echo “n===== test_msiTocEntry.tcl”
                                      echo “HciRoot ($HciRoot)”
                                      echo “HciSite ($HciSite)”
                                      echo “”

                                      msiAttach
                                      echo [msiTocEntry]
                                      msiDetach

                                      I got to wondering if msiDetach was even necessary when using a TCL wrapper approach like this so I commented it out and my test still worked fine with no complaints about aleady being attached.

                                      I find myself wondering If I understand how msiDetach is intended to be used because the next msiAttach after the first msiDetach never worked when inside the same TCL script and it doesn’t appear to be necessary when using a wrapper approach.

                                      Here is the output from running /hcitest/russ/test_changing_sites.tcl scripts

                                      Code:


                                      ########## method 1 proof of concept ##########
                                      HCI root is /cloverleaf/cis6.0/integrator
                                      HCI master site is mda_global
                                      HCI site is test_russ

                                      ===== test_msiTocEntry.tcl
                                      HciRoot (/cloverleaf/cis6.0/integrator)
                                      HciSite (test_picis)

                                      mock_picis_ormgr_v75_adt ob_picis_bldbank_ordrslts dump_picis_ormgr_v72_adt ob_lab_picis_v71 load_adt_picis_v71 dump_picis_ormgr_v75_adt ob_picis_ormgr_v81_adt ob_picis_lab_dev ob_adt_picis_v71 9216_test_lab ob_adt_picis_newserver rs_picis_ormgr_v72_adt jr_bldbnk_ordrslt load_picis_ormgr_v72_adt rs_picis_ormgr_v75_adt ob_picis_ormgr_v72_adt load_adt_ormgr_v72 ob_picis_ormgr_v75_lab mock_picis_ormgr_v72_adt 9231_test_adt load_picis_ormgr_v75_adt ob_picis_ormgr_v75_adt load_adt_ormgr_v75

                                      ===== test_msiTocEntry.tcl
                                      HciRoot (/cloverleaf/cis6.0/integrator)
                                      HciSite (test_ris)

                                      ob_syngo ob_pwrscribe jr_sms_genie_8238 ob_ris_train ib_ris_test_orders hsfw_8239 js_coderyte_10002 hrfw_8331 hrfw_8332 ob_stentor_adt ib_pwrscribe_ORU ib_syngo ib_ris_train_orders hrfw_8239 ob_ris_test ob_magview_oru hsfw_8331 ob_sms_la hsfw_8332

                                      ########## method 1 proof of concept ##########
                                      HCI root is /cloverleaf/cis6.0/integrator
                                      HCI master site is mda_global
                                      HCI site is test_ris

                                      ===== test_msiTocEntry.tcl
                                      HciRoot (/cloverleaf/cis6.0/integrator)
                                      HciSite (test_picis)

                                      mock_picis_ormgr_v75_adt ob_picis_bldbank_ordrslts dump_picis_ormgr_v72_adt ob_lab_picis_v71 load_adt_picis_v71 dump_picis_ormgr_v75_adt ob_picis_ormgr_v81_adt ob_picis_lab_dev ob_adt_picis_v71 9216_test_lab ob_adt_picis_newserver rs_picis_ormgr_v72_adt jr_bldbnk_ordrslt load_picis_ormgr_v72_adt rs_picis_ormgr_v75_adt ob_picis_ormgr_v72_adt load_adt_ormgr_v72 ob_picis_ormgr_v75_lab mock_picis_ormgr_v72_adt 9231_test_adt load_picis_ormgr_v75_adt ob_picis_ormgr_v75_adt load_adt_ormgr_v75

                                      ===== test_msiTocEntry.tcl
                                      HciRoot (/cloverleaf/cis6.0/integrator)
                                      HciSite (test_ris)

                                      ob_syngo ob_pwrscribe jr_sms_genie_8238 ob_ris_train ib_ris_test_orders hsfw_8239 js_coderyte_10002 hrfw_8331 hrfw_8332 ob_stentor_adt ib_pwrscribe_ORU ib_syngo ib_ris_train_orders hrfw_8239 ob_ris_test ob_magview_oru hsfw_8331 ob_sms_la hsfw_8332

                                      ########## Done ##########

                                      HCI root is /cloverleaf/cis6.0/integrator
                                      HCI master site is mda_global
                                      HCI site is test_ris

                                      Russ Ross
                                      RussRoss318@gmail.com

                                    • #82069
                                      Russ Ross
                                      Participant

                                        With regards to msiAttach, I consider it prudent to check to see if the $HCISIEDIR/exec/monitorShmemFile exist and if it doesn’t then I don’t run msiAttach.

                                        I don’t know about current versions of cloverleaf but in the past running msiAttach would create $HCISIEDIR/exec/monitorShmemFile after which mysterous problems would surface.

                                        This was an effective workaround since if no $HCISIEDIR/exec/monitorShmemFile exist, then the site most likely is not running.

                                        Here is an example:

                                        Code:

                                        if { [lsearch -exact [ls $HciSiteDir/exec] monitorShmemFile] == -1 } { exit }

                                        Russ Ross
                                        RussRoss318@gmail.com

                                      • #82070
                                        Bob Richardson
                                        Participant

                                          Greetings,

                                          Running CIS 6.1.0 on AIX 6 TL9 (HA virtualized).

                                          Russ, our Tcl programs that invoke the msiAttach comannd surround the call with a catch.  For a site we find that you can only call msiAttach once in a TCL instance (running program).  Otherwise you get an error but it is not fatal.  Keeps the return values “clean”.

                                          Sample code:

                                              if {$mode == “start”} {

                                                   catch {msiAttach}

                                              } elseif {$mode == “run”} {

                                                 set threadstats [msiGetStatSample $url_thread]

                                                 keylget threadstats OBDATAQD pend_count  ;#get the pending count for the requeue thread

                                          Hope this helps.

                                          Enjoy.

                                        • #82071
                                          Jeff Dinsmore
                                          Participant

                                            We are on 5.6, so don’t have msiDetach, but do recall attempting to just change sites and then run msiAttach again which just crashed and burned…

                                            So, to loop through all sites for diagnostic/monitoring, I found it necessary to exec a call to hcicmd to get thread/process info.

                                            Code:

                                            set resultList [lrange [exec hcicmd -p hcimonitord -t d -c “statusrpt {$crmcNetConfigArray($site,$process,threadList)}”] 2 end]

                                            I then evaluate the returned resultList and glean whatever info I’m looking for.

                                            Using exec was not my preference, but looked to be the only option for what I was trying to do.

                                            Jeff Dinsmore
                                            Chesapeake Regional Healthcare

                                          • #82072
                                            Todd Horst
                                            Participant

                                              Thanks jeff, that looks like the same data, without the messiness of msi.

                                              Russ, what you have works, i kind of wanted it to be one script, or at least have that ability.

                                              I started looking into interp. And made it pretty far, however I still get the same with when doing an msiAttach on a subsequent site.

                                              Code:

                                              set s [interp create]
                                              proc hello2 {} {
                                              puts “hello2”
                                              }

                                              proc mykeylkeys {arg} {
                                              return [keylkeys arg]
                                              }
                                              proc mykeylget {arg1 arg2} {
                                              return [keylget arg1 $arg2]
                                              }

                                              # Procs that they need access to
                                              interp alias $s hello2 {} hello2
                                              interp alias $s msiAttach {} msiAttach
                                              interp alias $s msiDetach {} msiDetach
                                              interp alias $s msiGetStatSample {} msiGetStatSample
                                              interp alias $s keylkeys {} mykeylkeys
                                              interp alias $s keylget {} mykeylget
                                              interp alias $s echo {} echo

                                              # Variables that they need access to
                                              interp eval $s [list “set” “threads” $threads]
                                              interp eval $s [list “set” “auto_path” $::auto_path]
                                              #interp eval $s [list “set” “env” $env]

                                              set threads [interp eval $s {
                                              proc hello {} {
                                              puts “hiya”
                                              }
                                              global env
                                              #hello
                                              #hello2
                                              #puts $auto_path
                                              msiAttach

                                              set idx -1
                                              foreach thread $threads {

                                              # Get name from dictionary
                                              set Name [dict get $thread Name]

                                              # Get stats
                                              set result [msiGetStatSample $Name]

                                              set StatKEYS [keylkeys $result]

                                              # Protocal Status (UP/DOWN/CONNECTING)
                                              set Status “Unknown”
                                              if {[lsearch -exact $StatKEYS “PSTATUS”] != -1} {
                                              set Status [string totitle [keylget $result PSTATUS]]
                                              }
                                              dict append thread Status $Status
                                              }
                                               
                                              msiDetach
                                              return $threads
                                              }]

                                              interp delete $s

                                              return the first site, but then the seoncd site gets the following error on attach

                                              Code:

                                              [0:TEST] oilSysSemOpen: ftok failedSem Name = /NetConfig Project Id : 70[0:TEST] msiGlobalInit: Can’t open guard sem: No such file or directorymsiGlobalInit: NetConfig = /NetConfig

                                              For now I think ill go with jeffs command

                                            • #82073
                                              Russ Ross
                                              Participant

                                                I find myself liking Jeff’s approach, too.

                                                I tested it on a site where the monitod wasn’t running and it returns an error code of 2, plus doesn’t start the monitord or create a shared memory file that can cause problems later on like it does with msiAttach.

                                                Russ Ross
                                                RussRoss318@gmail.com

                                            Viewing 19 reply threads
                                            • The forum ‘Cloverleaf’ is closed to new topics and replies.