U
    
W[ú  ã                   @   s:   d Z ddlmZ ddlmZ G dd„ dejƒZdd„ ZdS )	z>
Support for creating a service which runs a process monitor.
é    )Úusage)ÚProcessMonitorc                   @   s`   e Zd ZdZdZddddegddd	d
egddddegddddeggZg ZdZdd„ Z	dd„ Z
dS )ÚOptionszF
    Define the options accepted by the I{twistd procmon} plugin.
    z[procmon options] commandlineÚ	thresholdÚté   zRHow long a process has to live before the death is considered instant, in seconds.ÚkilltimeÚké   zpHow long a process being killed has to get its affairs in order before it gets killed with an unmaskable signal.ÚminrestartdelayÚmzLThe minimum time (in seconds) to wait before attempting to restart a processÚmaxrestartdelayÚMi  zLThe maximum time (in seconds) to wait before attempting to restart a processa`  procmon runs processes, monitors their progress, and restarts them when they
die.

procmon will not attempt to restart a process that appears to die instantly;
with each "instant" death (less than 1 second, by default), it will delay
approximately twice as long before restarting it. A successful run will reset
the counter.

Eg twistd procmon sleep 10c                 G   s   || d< dS )zQ
        Grab the command line that is going to be started and monitored
        ÚargsN© )Úselfr   r   r   ú;/usr/lib/python3/dist-packages/twisted/runner/procmontap.pyÚ	parseArgs0   s    zOptions.parseArgsc                 C   s   t | d ƒdk rt d¡‚dS )z)
        Check for dependencies.
        r   r   z$Please specify a process commandlineN)Úlenr   Z
UsageError)r   r   r   r   ÚpostOptions7   s    zOptions.postOptionsN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ZsynopsisÚfloatZoptParametersZoptFlagsZlongdescr   r   r   r   r   r   r      s&   þýþþör   c                 C   sL   t ƒ }| d |_| d |_| d |_| d |_| d | d ¡| d ¡ |S )Nr   r   r   r   ú r   )r   r   ZkillTimeZminRestartDelayZmaxRestartDelayZ
addProcessÚjoin)ZconfigÚsr   r   r   ÚmakeService@   s    



r   N)r   Ztwisted.pythonr   Ztwisted.runner.procmonr   r   r   r   r   r   r   Ú<module>   s   3