ó
sÁìVc           @   s>   d  d l  Z  d  d l Z d  d l Z d e f d „  ƒ  YZ d S(   iÿÿÿÿNt   Pidfilec           B   s;   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   sž       Manage a PID file. If a specific name is provided
    it and '"%s.oldpid" % name' will be used. Otherwise
    we create a temp file using os.mkstemp.
    c         C   s   | |  _  d  |  _ d  S(   N(   t   fnamet   Nonet   pid(   t   selfR   (    (    s`   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/pidfile.pyt   __init__   s    	c         C   s  |  j  ƒ  } | rJ | t j ƒ  k r( d  Sd } t | | |  j f ƒ ‚ n  | |  _ t j j |  j ƒ } | r” t j j | ƒ r” t d | ƒ ‚ n  t	 j
 d | ƒ \ } } t j | d |  j j d ƒ ƒ |  j rë t j | |  j ƒ n	 | |  _ t j | ƒ t j |  j d ƒ d  S(   Ns5   Already running on PID %s (or pid file '%s' is stale)s'   %s doesn't exist. Can't create pidfile.t   dirs   %s
s   utf-8i¤  (   t   validatet   ost   getpidt   RuntimeErrorR   R   t   patht   dirnamet   isdirt   tempfilet   mkstempt   writet   encodet   renamet   closet   chmod(   R   R   t   oldpidt   msgt   fdirt   fdR   (    (    s`   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/pidfile.pyt   create   s"    	 		c         C   s'   |  j  ƒ  | |  _ |  j |  j ƒ d  S(   N(   t   unlinkR   R   R   (   R   R   (    (    s`   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/pidfile.pyR   /   s    
	c         C   sg   yY t  |  j d ƒ  } t | j ƒ  p* d ƒ } Wd QX| |  j k rX t j |  j ƒ n  Wn n Xd S(   s    delete pidfilet   ri    N(   t   openR   t   intt   readR   R   R   (   R   t   ft   pid1(    (    s`   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/pidfile.pyR   4   s    c      	   C   sÙ   |  j  s d Sy• t |  j  d ƒ } } y t | j ƒ  ƒ } Wn t k
 rO d SXy t j | d ƒ | SWn0 t k
 rš } | j d t	 j
 k r” d S‚  n XWd QXWn0 t k
 rÔ } | j d t	 j k rÎ d S‚  n Xd S(   s-    Validate pidfile and make it stale if neededNR   i    (   R   R   R   R   t
   ValueErrorR   t   killt   OSErrort   argst   errnot   ESRCHt   IOErrort   ENOENT(   R   R   t   wpidt   e(    (    s`   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/pidfile.pyR   ?   s&    	(   t   __name__t
   __module__t   __doc__R   R   R   R   R   (    (    (    s`   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/pidfile.pyR       s   				(   R%   R   R   t   objectR    (    (    (    s`   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/pidfile.pyt   <module>   s   