-í
 ´§Ec       sz     d  k  Z   d  k Z  d  k Z  d  k Z  d  k Z  d  k Z 	 d  k Z 
 d  k Z  e i	 Z	  d Z
  d Z  d Z  d Z  d Z ! d Z " d Z # d Z & d Z ' d Z ) d g Z * d	 d
 e e f g Z + d d
 e e f g Z , e d g Z - d d d d e e f g Z 6 d „  Z N d „  Z [ d „  Z _ e d „ Z c d „  Z l d „  Z p d „  Z t e e  d „ Z! { e e  e  d „ Z" † e  d „ Z#  d „  Z$ ’ d „  Z% – d „  Z& › d „  Z' ¢ d e( f d  „  ƒ  YZ) © d! „  Z* ® d" „  Z+ ´ d# „  Z, ¾ d$ „  Z- d% „  Z. $d& „  Z/ /d' „  Z0 5d( „  Z1 Md) „  Z2 ˆe	 i3 d* ƒ ‰e	 i4 e	 i5 ƒ ‹e6 e i7 ƒ d+ j  o Œe ƒ  e i8 d ƒ n y e  i9 d, Z: Wn* ‘’e	 i; d- ƒ “e i8 d. ƒ n X•y –e  i9 d/ Z< Wn* —˜e	 i; d0 ƒ ™e i8 d. ƒ n X¿e= e i7 d ƒ Ày² Áe6 e> ƒ d j o$ Âe	 i; d1 ƒ Ãe i8 d. ƒ n Äe6 e? ƒ d j o$ Åe	 i; d2 ƒ Æe i8 d. ƒ n Çe6 e@ ƒ d j o$ Èe	 i; d3 ƒ Ée i8 d. ƒ n WnB ÊeA j
 o3 ZB Ëe	 i; d4 eB iC ƒ  ƒ Ìe i8 d. ƒ n XÎh  ZD Ïe? d+ f e@ d+ f g ZE Ñe i7 d d5 j o Òe- e? ƒ nÃ Ôe i7 d d6 j o Õe- e@ ƒ n› ×e i7 d d7 j o Øe/ d ƒ ns Úe i7 d d8 j o Ûe0 ƒ  nN Ýe i7 d d9 j o Þe2 eE ƒ n& áe	 i; d: e i7 d ƒ âe ƒ  d  S(;   Ni    i   iöÿÿÿi
   i   s	   localhosti   s   SystemEventChannels   -ORBIIOPAddrs
   inet:%s:%us   -ORBNamingAddrs   -ORBIIOPBlockings   -ORBids   omniORB3s   -ORBInitRefs   NameService=corbaname::%s:%uc     s>   6 7 d t  i d }  J t i |  ƒ K t  i i |  ƒ d  S(   NsL  
Usage: %s <config file> <command>

Where command is one of:

    start - Starts all the required processes and exits.

    startdata - Starts the data related processes and exits.

    stop -  Stops all the processes.

    status - Display status for the processes.

    spawn - Start all the required processes and then monitor them.
        When a required process dies, restart all of the processes.
        Restart all processes on receipt of a SIGUSR1 signal.
	Stop all processes and reboot on receipt of a SIGUSR2 signal.
	Stop all processes on receipt of other catchable signals.
i    (   s   syss   argvs   ss   Logs   infos   stderrs   write(   s   s(    (    s	   istard.pys   usage6 s   c    s“   N O t  i |  ƒ o P d t  i |  ƒ Snb Q t  i |  ƒ o R d t  i |  ƒ Sn7 S t  i |  ƒ o T d t  i |  ƒ Sn V d |  Sd  S(   Ns   exited with status %ds   exited on signal %ds   stopped on signal %ds   returned unknown status %d(   s   oss	   WIFEXITEDs   statuss   WEXITSTATUSs   WIFSIGNALEDs   WTERMSIGs
   WIFSTOPPEDs   WSTOPSIG(   s   status(    (    s	   istard.pys   exitDescriptionN s   c    s   [ \ d t  |  f Sd  S(   Ns   %s/data/pid/%s.pid(   s
   TWCPERSDIRs   appName(   s   appName(    (    s	   istard.pys   makePidfileName[ s   c    s   _ ` |  t | | f Sd  S(   N(   s   pid_types	   PERM_PROCs
   nice_levels   args(   s   pid_types   argss
   nice_level(    (    s	   istard.pys   permProc_ s   c    s   c d t  t t |  f Sd  S(   N(   s   NO_PIDs	   TEMP_PROCs   DFLT_PRIs   args(   s   args(    (    s	   istard.pys   tempProcc s   c    s!   l m t  t |  |  g | ƒ Sd  S(   N(   s   permProcs   MK_PIDs   names   args(   s   names   args(    (    s	   istard.pys
   micoBinaryl s   c    s   p q t  d d |  g ƒ Sd  S(   Ns   sleep(   s   tempProcs   secs(   s   secs(    (    s	   istard.pys   sleepp s   c    s[   t u | t j o v |  } n w |  | g t d t | f g } x t t | | ƒ Sd  S(   Ns   %s/conf/%s.py(	   s   confs   Nones   procs	   corbaArgss
   TWCPERSDIRs   argss   permProcs   WT_PIDs   pri(   s   procs   pris   confs   args(    (    s	   istard.pys   istarBinaryt s   $c    s   { | | t j o } |  } n ~ | t j o  t } n € d | d | |  f d t | f g t } ƒ t t	 | | ƒ Sd  S(   Ns   pythons   %s/bin/%s/main.pycs   %s/conf/%s.py(   s   confs   Nones   scripts   dirs	   TWCCLIDIRs
   TWCPERSDIRs   omniOrbArgss   argss   permProcs   WT_PIDs   pri(   s   scripts   pris   confs   dirs   args(    (    s	   istard.pys   pythonDaemon{ s   -c    sU   † ‡ d |  d t |  f g } ˆ | t j o ‰ | | } n Š t | t ƒ Sd  S(   Ns   pythons   %s/util/%s.pyc(   s   scripts	   TWCCLIDIRs   argvs   argss   Nones   tempProcs   omniOrbArgs(   s   scripts   argss   argv(    (    s	   istard.pys
   pythonUtil† s   c    s:    Ž d |  | f d t | ƒ g }  t d | ƒ Sd  S(   Ns   %s.%ss   "%s"s   signalEvent(   s   procs   signals   reprs   argss   argvs
   pythonUtil(   s   procs   signals   argss   argv(    (    s	   istard.pys
   sendSignal s   #c    s%   ’ “ t  |  d |  d | f ƒ Sd  S(   Ns
   loadPlugins   .(   s
   sendSignals   procs   plugin(   s   procs   plugin(    (    s	   istard.pys
   loadPlugin’ s   c    s'   – — t  d d ˜ d t |  f ƒ Sd  S(   Ns   playmans   playCmd.rsload.loads   %s/products/local(   s
   sendSignals
   TWCPERSDIRs   product(   s   product(    (    s	   istard.pys   loadProduct– s   c    s   › œ t  d |  g ƒ Sd  S(   Ns   load(   s
   pythonUtils   script(   s   script(    (    s	   istard.pys   rsload› s   s   MyErrorc      s   ¢ £ d „  Z  ¥ d „  Z RS(   Nc    s   £ ¤ | |  _  d  S(   N(   s   values   self(   s   selfs   value(    (    s	   istard.pys   __init__£ s   c    s   ¥ ¦ |  i Sd  S(   N(   s   selfs   value(   s   self(    (    s	   istard.pys   __str__¥ s   (   s   __init__s   __str__(    (    (    s	   istard.pys   MyError¢ s   c    s4   © ª t  i d |  ƒ « t ƒ  ¬ t |  ƒ ‚ d  S(   Ns   Got signal %d(   s   Logs   errors   signums   disable_signal_handlers   MyError(   s   signums   frame(    (    s	   istard.pys   signal_handler© s   
c      sR   ® ° t  i  t  i t  i ƒ ± t  i  t  i t  i ƒ ² t  i  t  i t  i ƒ d  S(   N(   s   signals   SIGUSR1s   SIG_DFLs   SIGUSR2s   SIGTERM(    (    (    s	   istard.pys   disable_signal_handler® s   c      sŽ   ´ · t  i d t i ƒ ¸ t i t i t ƒ ¹ t  i d t i ƒ º t i t i t ƒ » t  i d t i ƒ ¼ t i t i t ƒ d  S(   Ns#   trapping SIGUSR1 - signal number %ds#   trapping SIGUSR2 - signal number %ds#   trapping SIGTERM - signal number %d(   s   Logs   infos   signals   SIGUSR1s   signal_handlers   SIGUSR2s   SIGTERM(    (    (    s	   istard.pys   enable_signal_handler´ s   c    sN  ¾ ¿ xA|  D¿ ]6\ } } } } Ä | d } Å t | ƒ } Ç | t j ošÉ t	 i
 i | ƒ o Ê t	 i | ƒ n Ì t i d | d | d f ƒ Í t	 i t	 i | d | d ƒ } Ï t i d | | f ƒ Ð | t | <Ò | t j oo Ô t i d ƒ Ø y7 Ù t | d ƒ } Ú | i d | ƒ Û | i ƒ  Wn Ü Ý t i d | ƒ n Xn:â d } ã d	 }
 ä d } å d } ç x² ç | | j  o¡ ì t i |
 ƒ í | |
 } ð t	 i | t	 i  ƒ \ } }	 ñ | | j o+ ò t i d
 | | t# |	 ƒ f ƒ õ Pn ÷ t	 i
 i | ƒ o ù d } ú Pn qWü | d j oM ý t i d | f ƒ þ t i d | t# |	 ƒ f ƒ  t$ t% i& ƒ ‚ n | t' j o8 t i d | | f ƒ t	 i( d | | f ƒ n n_ 
t i d t) i* | d  | d ƒ ƒ t	 i( t) i* | d  | d ƒ ƒ t i d ƒ q Wd  S(   Ni   s   spawnvp args are %s %si    s   %s pid was %ds   ws   %d
s   unable to create pidfile %sf5.0f0.10000000000000001s   Pid %d (%s) %ss.   Process %s failed to start. Raising exception.s   cpid = %d: %ss   doing renice %d -p %ds   sudo renice %d -p %ds   os.system args are %si   (+   s   commandLists   pidfile_types	   proc_types
   nice_levels   cmdlists   appNames   makePidfileNames   pidfileNames	   PERM_PROCs   oss   paths   isfiles   unlinks   Logs   infos   spawnvps   P_NOWAITs   pids   critical_pidss   MK_PIDs   times   sleeps   files   pidfiles   writes   closes   criticals	   timeLimits	   sleepTimes   elapsedTimes   founds   waitpids   WNOHANGs   cpids   cstats   exitDescriptions   MyErrors   signals   SIGUSR1s   DFLT_PRIs   systems   strings   join(   s   commandLists   cpids   appNames   pids	   timeLimits
   nice_levels   cmdlists   pidfile_types	   proc_types   cstats	   sleepTimes   elapsedTimes   founds   pidfileNames   pidfile(    (    s	   istard.pys   start_processes¾ sX   
 "#				 #	 ")%c    s,  t  i i |  ƒ oy× t t |  ƒ i ƒ  i ƒ  ƒ } | d j o¢ t	 i
 d | ƒ yO t  i | t i ƒ | o+ t  i | d ƒ t	 i
 d | ƒ n Wn5 t j
 o& } t	 i
 d | i | f ƒ n Xn Wn  t	 i d |  ƒ n X"t  i |  ƒ n d  S(   Ni   s   killing process with pid = %di    s   process %d dieds   Error %d trying to kill %ds   Error getting pid from %s(   s   oss   paths   isfiles   pidFilenames   ints   opens   readlines   strips   pids   Logs   infos   kills   signals   SIGTERMs   waits   waitpids   OSErrors   es   errnos   errors   unlink(   s   pidFilenames   waits   es   pid(    (    s	   istard.pys   kill_pidfiles   !
*c    sj   $'x' t  D'] } (t t | ƒ |  ƒ q W,x0 t i t d ƒ ƒ D,] } -t | |  ƒ qI Wd  S(   Ns   *(   s   stopCmdLists   appNames   kill_pidfiles   makePidfileNames   waits   globs   pidFilename(   s   waits   appNames   pidFilename(    (    s	   istard.pys   stop_processes$s   
 	 	c     sH   /0d }  1x" t D1] } 2|  d | 7}  q W3t i |  ƒ d  S(   Ns   ps | grep -v grep | egrep s   -e "%s" (   s   cmds   stopCmdLists   names   oss   system(   s   cmds   name(    (    s	   istard.pys   disp_processes/s
   	
 	c     sõ   56t  i  ƒ  } 7xÙ 7d oÎ 8t i d ƒ 9t i ƒ  \ }  } :t i	 |  ƒ ol ;t i
 d t |  |  t | ƒ f ƒ @t  i  ƒ  | d j  o At t i ƒ ‚ n Dt d ƒ GPn' It i d |  t | ƒ f ƒ Kq q Wd  S(   Ni   s"   Waiting for a child process to dies&   Permament child process %s (pid %d) %ss#   Temporary child process (pid %d) %s(   s   times   starts   Logs   infos   oss   waits   cpids   cstats   critical_pidss   has_keys   criticals   exitDescriptions   MyErrors   signals   SIGUSR1s   stop_processess   error(   s   cpids   starts   cstat(    (    s	   istard.pys   listen_for_dead_child_processes5s    
' c    s”  MNt  ƒ  Pd } Qd } RxN|  DR]C\ } } Sd } TxÒT| | j oÁUyu Wh  } Y| | j oX Z| d } [t | ƒ \t	 ƒ  ]d } ^| o _d } n `t
 i d ƒ n WnBbt j
 oý } ct
 i d | i ƒ d| i t i j o! et
 i d ƒ ft d ƒ n g| i t i j oI ht
 i d ƒ id GHjt i d ƒ kt d ƒ lt i d ƒ n m| i t i j o1 nt
 i d ƒ ot d ƒ pt i d ƒ n n8 rst
 i d	 ƒ tt d ƒ ut i d
 ƒ n XqG Wv| o | o< wt
 i d ƒ xd GHyt i d ƒ zt i d ƒ n {d } q) W}t
 i d ƒ ~t i ƒ  d  S(   Ni   i    s.   Child process died. Need to RESTART processes.s!   MyError exception - signal was %ds%   SIGUSR1 triggered. Stopping processess   REBOOTING system in 1 minutes   shutdown -r +1s%   SIGTERM triggered. Stopping processess   Unexpected exception.iþÿÿÿs    REBOOTING due to restart failures   shutdown -r nows(   Failed all attempts to restart. Hanging.(   s   enable_signal_handlers   firsts   successful_runs   commandListss   command_lists   max_attemptss   attempts_mades   critical_pidss   start_processess   listen_for_dead_child_processess   Logs   criticals   MyErrors   es   values   signals   SIGUSR1s   infos   stop_processess   SIGUSR2s   oss   systems   syss   exits   SIGTERMs   pause(   s   commandListss   es   command_lists   critical_pidss   attempts_mades   max_attemptss   successful_runs   first(    (    s	   istard.pys   spawn_processesMsZ   
		
 	 	
	
s   istardi   s	   TWCCLIDIRs*   No TWCCLIDIR environment variable defined!iÿÿÿÿs
   TWCPERSDIRs+   No TWCPERSDIR environment variable defined!s   Error: stopCmdList is emptys   Error: startCmdList is emptys    Error: startDataCmdList is emptys	   Error: %ss   starts	   startdatas   stops   statuss   spawns   Unknown argument: %s(F   s   oss   syss   times   strings   signals   globs   twcs   twccommon.Logs	   twccommons   Logs	   TEMP_PROCs	   PERM_PROCs   HIGH_PRIs   DFLT_PRIs   LOW_PRIs   NO_PIDs   MK_PIDs   WT_PIDs   hostNames   basePorts   eventChannelNameArgs   nsdArgss   orbNameArgss	   corbaArgss   omniOrbArgss   usages   exitDescriptions   makePidfileNames   permProcs   tempProcs
   micoBinarys   sleeps   Nones   istarBinarys   pythonDaemons
   pythonUtils
   sendSignals
   loadPlugins   loadProducts   rsloads	   Exceptions   MyErrors   signal_handlers   disable_signal_handlers   enable_signal_handlers   start_processess   kill_pidfiles   stop_processess   disp_processess   listen_for_dead_child_processess   spawn_processess   setIdents   setLevels   INFOs   lens   argvs   exits   environs	   TWCCLIDIRs   criticals
   TWCPERSDIRs   execfiles   stopCmdLists   startCmdLists   startDataCmdLists	   NameErrors   es   __str__s   critical_pidss   ListOfCmdLists(5   s	   PERM_PROCs   Logs   loadProducts   hostNames   omniOrbArgss
   loadPlugins   sleeps   MK_PIDs   WT_PIDs   twcs   rsloads   signals   pythonDaemons
   sendSignals
   micoBinarys   spawn_processess   exitDescriptions   disp_processess   critical_pidss   tempProcs   usages   listen_for_dead_child_processess   basePorts   nsdArgss   disable_signal_handlers   permProcs   MyErrors   strings   orbNameArgss   enable_signal_handlers   globs   syss   kill_pidfiles   ListOfCmdListss	   TWCCLIDIRs   makePidfileNames
   TWCPERSDIRs   NO_PIDs   LOW_PRIs   start_processess   stop_processess   signal_handlers   es   istarBinarys   DFLT_PRIs   HIGH_PRIs   eventChannelNameArgs
   pythonUtils	   twccommons   times	   TEMP_PROCs   oss	   corbaArgs(    (    s	   istard.pys   ? s´   												
Q;
&	