
    Ϫf	                     j    d Z ddlmZmZ ddlmZ ddlmZ  G d dej                        Zdedefd	Z	y
)z>
Support for creating a service which runs a process monitor.
    )ListSequence)usage)ProcessMonitorc                       e Zd ZU 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ee	e
      ed<   dZde
ddfdZddZy)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 processoptFlagsa`  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 10argsreturnNc                     || d<   y)zQ
        Grab the command line that is going to be started and monitored
        r   N )selfr   s     ;/usr/lib/python3/dist-packages/twisted/runner/procmontap.py	parseArgszOptions.parseArgsI   s     V    c                 P    t        | d         dk  rt        j                  d      y)z)
        Check for dependencies.
        r   r   z$Please specify a process commandlineN)lenr   
UsageError)r   s    r   postOptionszOptions.postOptionsO   s,     tF|q ""#IJJ !r   )r   N)__name__
__module____qualname____doc__synopsisfloatoptParametersr   r   r   str__annotations__longdescr   r   r   r   r   r   r      s     /H B	
 ) 	
  	
  	
7$ML %'Hd8C=!&	Hs t Kr   r   configr   c                     t               }| d   |_        | d   |_        | d   |_        | d   |_        |j                  dj                  | d         | d          |S )Nr	   r   r   r    r   )r   r	   killTimeminRestartDelaymaxRestartDelay
addProcessjoin)r*   ss     r   makeServicer3   W   sb    A%AK
#AJ01A01ALL&.)6&>:Hr   N)
r#   typingr   r   twisted.pythonr   twisted.runner.procmonr   r   r3   r   r   r   <module>r7      s=   
 "   1EKemm EKP	 	N 	r   