mò
Ž»Lc           @   s¶   d  k  Z  d  k Z  d  k Z d k Td  k Z d d d d d g Z h  d d <d d <d d	 <d d
 <d d <Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z d „  Z d  S(   N(   t   *t   startt   stopt   restartt   pidt   outs'   Start the application in the backgrounds   Stop the running applications   Restart the running applications'   Show the PID of the running applications   Follow logs/system.out filec          K   sÍ   |  i d ƒ } |  i d ƒ } |  i d ƒ } |  i d ƒ } | d j o t | | ƒ n | d j o t | ƒ n | d j o t | | ƒ n | d j o t	 | ƒ n | d	 j o t
 | ƒ n d  S(
   Nt   commandt   appt   argst   envR   R   R   R   R   (   t   kargst   getR   R   R   t   play_envR   R   R   R   R   (   R
   R   R   R   R   (    (    t`   /afs/cs.wisc.edu/p/zhu/public/html/space2/dualist/play-1.1/framework/pym/play/commands/daemon.pyt   execute   s    c         C   s£  |  i ƒ  t i i |  i ƒ  ƒ oF d t i i |  i ƒ t i i |  i ƒ  ƒ f GHd GHt i d ƒ n |  i	 d ƒ } | d j o
 | d j } | p
 d  } n% t t i i |  i ƒ  d ƒ d ƒ } y. t i |  i | ƒ d	 | d
 t i ƒi } Wn% t j
 o d GHt i d ƒ n Xd t i i |  i ƒ GH| o. d t i i t i i |  i ƒ  d ƒ ƒ GHn t |  i ƒ  d ƒ } | i t | ƒ ƒ d | GHd GHd  S(   Ns-   ~ Oops. %s is already started! (or delete %s)t   ~i   s   application.log.system.outt   falset   offs
   system.outt   wt   stdoutR	   s¦   Could not execute the java executable, please make sure the JAVA_HOME environment variable is set properly (the java executable should reside at JAVA_HOME/bin/java). iÿÿÿÿs   ~ OK, %s is starteds   ~ output is redirected to %ss   ~ pid is %s(   R   t   checkt   ost   patht   existst   pid_patht   normpatht   syst   exitt   readConft   sysoutt   Nonet   soutt   opent   joint   log_patht
   subprocesst   Popent   java_cmdR   t   environR   t   OSErrort   pid_filet   writet   str(   R   R   R   R   R   R(   (    (    R   R   !   s,    
0
$..	c         C   s¡   |  i ƒ  t i i |  i ƒ  ƒ p. d t i i |  i ƒ GHd GHt i d ƒ n t	 |  i ƒ  ƒ i
 ƒ  i ƒ  } t i |  i ƒ  ƒ t | ƒ d |  i GHd GHd  S(   Ns0   ~ Oops! %s is not started (server.pid not found)R   iÿÿÿÿs   ~ OK, %s is stopped(   R   R   R   R   R   R   R   R   R   R    t   readlinet   stripR   t   removet   kill(   R   R   (    (    R   R   ;   s    

c         C   sÌ  |  i ƒ  t i i |  i ƒ  ƒ p! d t i i |  i ƒ GHd GHn< t |  i ƒ  ƒ i ƒ  i	 ƒ  } t i |  i ƒ  ƒ t | ƒ |  i d ƒ } | d j o
 | d j } |  i | ƒ } | p
 d  } n% t t i i |  i ƒ  d ƒ d ƒ } y% t i | d | d	 t i ƒi
 } Wn% t j
 o d
 GHt i d ƒ n Xd t i i |  i ƒ GH| o. d t i i t i i |  i ƒ  d ƒ ƒ GHn t |  i ƒ  d ƒ } | i t | ƒ ƒ d | GHd GHt i d ƒ d  S(   Ns0   ~ Oops! %s is not started (server.pid not found)R   s   application.log.system.outR   R   s
   system.outR   R   R	   s¦   Could not execute the java executable, please make sure the JAVA_HOME environment variable is set properly (the java executable should reside at JAVA_HOME/bin/java). iÿÿÿÿs   ~ OK, %s is restarteds   ~ output is redirected to %ss   ~ New pid is %si    (   R   R   R   R   R   R   R   R    R+   R,   R   R-   R.   R   R   R%   R   R   R   R!   R"   R#   R$   R&   R'   R   R   R(   R)   R*   (   R   R   R%   R   R   R   R(   (    (    R   R   H   s4    
	

$%.	c         C   s   |  i ƒ  t i i |  i ƒ  ƒ p. d t i i |  i ƒ GHd GHt i d ƒ n t	 |  i ƒ  ƒ i
 ƒ  i ƒ  } d | GHd GHd  S(   Ns0   ~ Oops! %s is not started (server.pid not found)R   iÿÿÿÿs'   ~ PID of the running applications is %ss   ~ (   R   R   R   R   R   R   R   R   R   R    R+   R,   R   (   R   R   (    (    R   R   h   s    
	c         C   s+  |  i ƒ  t i i t i i |  i ƒ  d ƒ ƒ p@ d t i i t i i |  i ƒ  d ƒ ƒ GHd GHt i	 d ƒ n t
 t i i |  i ƒ  d ƒ d ƒ } y | i d t i ƒ Wn  t j
 o | i d ƒ n XxT t oL | i ƒ  } | i ƒ  i ƒ  } | p t i d ƒ | i | ƒ qÓ | GHqÓ Wd  S(	   Ns
   system.outs   ~ Oops! %s not foundR   iÿÿÿÿt   rixìÿÿi    i   (   R   R   R   R   R   R!   R"   R   R   R   R    R   t   seekt   SEEK_ENDt   IOErrort   Truet   tellt   whereR+   R,   t   linet   timet   sleep(   R   R5   R   R6   (    (    R   R   r   s$    
(*$ c         C   s×   t  i d j ox d  k } | i i i d t t |  ƒ ƒ } | i i i
 | d ƒ p1 d |  | i i i ƒ  f GHd GHt i d ƒ qÓ nL y t  i t |  ƒ d ƒ Wn. t j
 o" d |  GHd	 GHt i d ƒ n Xd  S(
   Nt   nti   i    s0   ~ Cannot kill the process with pid %s (ERROR %s)s   ~ iÿÿÿÿi   s0   ~ Play was not running (Process id %s not found)R   (   R   t   namet   ctypest   windllt   kernel32t   OpenProcesst   Falset   intR   t   handlet   TerminateProcesst   GetLastErrorR   R   R.   R'   (   R   RA   R;   (    (    R   R.   †   s    	!	(   R   t   os.pathR#   t
   play.utilsR7   t   COMMANDSt   HELPR   R   R   R   R   R   R.   (   RF   RG   R   R   R   R#   R   R.   R7   R   R   R   (    (    R   t   ?   s   		3				 	
	