+
    jG                     >    R t ^ RIt^ RIt^ RIt^ RIt ! R R4      tR# )zn
Control Interface Command Handlers

Provides handlers for all control commands with access to arbiter state.
Nc                   p  a  ] tR t^t o RtR tV 3R lR ltV 3R lR ltV 3R lR ltV 3R	 lR
 lt	V 3R lR lt
R'V 3R lR lltR'V 3R lR lltV 3R lR ltR'V 3R lR lltR'V 3R lR lltV 3R lR ltV 3R lR ltV 3R lR ltR(V 3R lR lltV 3R lR  ltV 3R! lR" ltV 3R# lR$ ltR%tV tR&# ))CommandHandlersz
Command handlers with access to arbiter state.

All handler methods return dictionaries that will be sent
as the response data.
c                    Wn         R# )z_
Initialize handlers with arbiter reference.

Args:
    arbiter: The Gunicorn arbiter instance
Narbiter)selfr   s   &&J/var/www/idalgo/venv/lib/python3.14/site-packages/gunicorn/ctl/handlers.py__init__CommandHandlers.__init__   s	         c                    < V ^8  d   QhRS[ /#    returndict)format__classdict__s   "r   __annotate__CommandHandlers.__annotate__"   s     !; !;d !;r   c                   . p\         P                  ! 4       pV P                  P                  P	                  4        Fk  w  r4 VP
                  P                  4       p\        W%,
          ^4      pVP                  RVRVP                  RVP                  RVP                  RV/4       Km  	  VP                  R R7       R	VR
\        V4      /#   \        \        3 d    Rp Lti ; i)a5  
Return list of HTTP workers.

Returns:
    Dictionary with workers list containing:
    - pid: Worker process ID
    - age: Worker age (spawn order)
    - requests: Number of requests handled (if available)
    - booted: Whether worker has finished booting
    - last_heartbeat: Seconds since last heartbeat
Npidagebootedabortedlast_heartbeatc                     V R ,          # r    ws   &r   <lambda>.CommandHandlers.show_workers.<locals>.<lambda>A   s    1U8r   keyworkerscount)time	monotonicr   WORKERSitemstmplast_updateroundOSError
ValueErrorappendr   r   r   sortlen)r   r%   nowr   workerr,   r   s   &      r   show_workersCommandHandlers.show_workers"   s     nn<<//557KC&$jj446!&s'8!!< NNsvzz&--6>> .  8  	+,7GS\:: Z( &!%&s   ,CC#"C#c                    < V ^8  d   QhRS[ /# r   r   )r   r   s   "r   r   r   E   s     :
 :
D :
r   c                   V P                   P                  '       g   RRRRR. R. /# \        V P                   RR4      p. p. pV'       Ed?   \        VR4      '       Ed,   \        P
                  ! 4       pVP                  P                  4        Fm  w  rV VP                  P                  4       p\        WG,
          ^4      pVP                  RVRVP                  R\        VR	. 4      R
\        VR
R4      RV/4       Ko  	  \        VR4      '       dz   VP                   P                  4        F[  w  r\#        VP$                  P'                  V	. 4      4      pVP                  RV	RV
P'                  R4      R\)        V4      RV/4       K]  	  RRRV P                   P                  RVRV/#   \        \        \        3 d    Rp ELi ; i)z
Return dirty workers and apps information.

Returns:
    Dictionary with:
    - enabled: Whether dirty arbiter is running
    - pid: Dirty arbiter PID
    - workers: List of dirty worker info
    - apps: List of dirty app specs
enabledFr   Nr%   appsdirty_arbiterr   	app_pathsr   r   	app_specsimport_pathworker_countcurrent_workersworker_pidsT)r   dirty_arbiter_pidgetattrhasattrr'   r(   r%   r*   r+   r,   r-   r.   r/   AttributeErrorr0   r   r=   listapp_worker_mapgetr2   )r   r;   r%   r:   r3   r   r4   r,   r   pathspecrA   s   &           r   
show_dirtyCommandHandlers.show_dirtyE   s    ||---5t2	   otD=W]I>>.."C,44::<*"(**"8"8":K%*3+<a%@N 36::GFK<gfh>$n    =  }k22"/"9"9"?"?"AJD"&}'C'C'G'Gb'Q"RKKK%t&(@)3{+;%{	!  #B t4<<11wD	
 	
-  ^< *%)N*s   ,F''GGc                    < V ^8  d   QhRS[ /# r   r   )r   r   s   "r   r   r      s     ! !T !r   c                |   V P                   P                  p/ p. ROpV F  p \        W4      p\        V4      '       d   \	        V4      pMW\        VR4      '       dF   \        V\        \        \        \        \        \        \        R4      34      '       g   \	        V4      pWRV&   K  	  V#   \         d     K  i ; i)zZ
Return current effective configuration.

Returns:
    Dictionary of configuration values
	__class__N)bindr%   worker_classthreadstimeoutgraceful_timeout	keepalivemax_requestsmax_requests_jitterworker_connectionspreload_appdaemonpidfile	proc_namereloaddirty_workers
dirty_appsdirty_timeoutcontrol_socketcontrol_socket_disable)r   cfgrC   callablestrrD   
isinstanceintfloatboolrF   r   typerE   )r   rc   configconfig_keysr$   values   &     r   show_configCommandHandlers.show_config   s     ll
 C
)E??JEUK00S%tT4:N:P :PJE#s   " s   BB,,B;:B;c                    < V ^8  d   QhRS[ /# r   r   )r   r   s   "r   r   r      s     
 
D 
r   c                   \        V P                  R/ 4      pVP                  R4      pRpV'       d'   \        \        P                  ! 4       V,
          ^4      pRTRV P                  P
                  R\        V P                  P                  4      RV P                  P                  RVP                  R^ 4      R	VP                  R	^ 4      R
VP                  R
^ 4      RV P                  P                  ;'       g    R/# )aA  
Return server statistics.

Returns:
    Dictionary with:
    - uptime: Seconds since arbiter started
    - pid: Arbiter PID
    - workers_current: Current number of workers
    - workers_spawned: Total workers spawned
    - workers_killed: Total workers killed (if tracked)
    - reloads: Number of reloads (if tracked)
_stats
start_timeNuptimer   workers_currentworkers_targetworkers_spawnedworkers_killedreloadsrB   )
rC   r   rH   r-   r'   r   r2   r)   num_workersrB   )r   statsrs   rt   s   &   r   
show_statsCommandHandlers.show_stats   s     h3YY|,
499;3Q7F f4<<##s4<<#7#78dll66uyy):A>eii(8!<uyyA.!?!?!G!G4	
 		
r   c                    < V ^8  d   QhRS[ /# r   r   )r   r   s   "r   r   r      s     A A Ar   c                   . pV P                   P                   F  p\        V4      pRVRVP                  4       /p VP                  pVP
                  \        P                  8X  d   RVR&   MIVP
                  \        P                  8X  d   RVR&   M$VP
                  \        P                  8X  d   RVR&   VP                  V4       K  	  RVR	\        V4      /#   \         d	    RTR&    L6i ; i)
zO
Return bound socket information.

Returns:
    Dictionary with listeners list
addressfdunixrj   tcptcp6unknown	listenersr&   )r   	LISTENERSre   filenosockfamilysocketAF_UNIXAF_INETAF_INET6	Exceptionr0   r2   )r   r   lnraddrlistener_infor   s   &     r   show_listenersCommandHandlers.show_listeners   s     	<<))Cs8D4cjjlM	2xx;;&..0,2M&)[[FNN2,1M&)[[FOO3,2M&) ]+' ** YY@@  2(1f%2s   0C-$C$CC-,C-c                &   < V ^8  d   QhRS[ RS[/# r   r&   r   rg   r   )r   r   s   "r   r   r      s     
 
 
D 
r   c                
   \        ^\        V4      4      pV P                  P                  pV P                  ;P                  V,          un        V P                  P	                  4        RVRVRV P                  P                  /# )z
Increase worker count.

Args:
    count: Number of workers to add (default 1)

Returns:
    Dictionary with added count and new total
addedprevioustotalmaxrg   r   rz   wakeup)r   r&   	old_counts   && r   
worker_addCommandHandlers.worker_add   so     As5z"LL,,	  E)  	 U	T\\--
 	
r   c                &   < V ^8  d   QhRS[ RS[/# r   r   )r   r   s   "r   r   r      s     
 
3 
t 
r   c                    \        ^\        V4      4      pV P                  P                  p\        ^W!,
          4      pW#,
          pW0P                  n        V P                  P	                  4        RVRVRV/# )z
Decrease worker count.

Args:
    count: Number of workers to remove (default 1)

Returns:
    Dictionary with removed count and new total
removedr   r   r   )r   r&   r   	new_countactual_removeds   &&   r   worker_removeCommandHandlers.worker_remove   ss     As5z"LL,,	 9,-	".#,  	 ~	Y
 	
r   c                &   < V ^8  d   QhRS[ RS[/# )r   r   r   r   )r   r   s   "r   r   r     s      s t r   c                   \        V4      pWP                  P                  9  d   RRRRV R2/#  \        P                  ! V\
        P                  4       RRRV/#   \         d   pRRR\        T4      /u Rp?# Rp?ii ; i)	z}
Gracefully terminate a specific worker.

Args:
    pid: Worker process ID

Returns:
    Dictionary with killed PID or error
successFerrorzWorker z
 not foundTkilledN)	rg   r   r)   oskillsignalSIGTERMr.   re   )r   r   es   && r   worker_killCommandHandlers.worker_kill  s     #hll***573%z2 

	GGC(4#   	5Q 	s   *A B 'A;5B ;B c                &   < V ^8  d   QhRS[ RS[/# r   r   )r   r   s   "r   r   r   4  s     7 7s 74 7r   c                    V P                   P                  '       g   RRRR/# \        ^\        V4      4      pV P	                  RV4      # )z
Spawn additional dirty workers.

Sends a MANAGE message to the dirty arbiter to spawn workers.

Args:
    count: Number of dirty workers to add (default 1)

Returns:
    Dictionary with added count or error
r   Fr   Dirty arbiter not runningaddr   rB   r   rg   _send_manage_messager   r&   s   &&r   	dirty_addCommandHandlers.dirty_add4  sN     ||---54 
 As5z"((66r   c                &   < V ^8  d   QhRS[ RS[/# r   r   )r   r   s   "r   r   r   I  s     : :# :d :r   c                    V P                   P                  '       g   RRRR/# \        ^\        V4      4      pV P	                  RV4      # )z
Remove dirty workers.

Sends a MANAGE message to the dirty arbiter to remove workers.

Args:
    count: Number of dirty workers to remove (default 1)

Returns:
    Dictionary with removed count or error
r   Fr   r   remover   r   s   &&r   dirty_removeCommandHandlers.dirty_removeI  sN     ||---54 
 As5z"((599r   c                ,   < V ^8  d   QhRS[ RS[RS[/# )r   	operationr&   r   )re   rg   r   )r   r   s   "r   r   r   ^  s'     C Cc C# C$ Cr   c           	        Rp\        V P                  R4      '       d>   V P                  P                  '       d"   \        V P                  P                  RR4      pV'       g    \        P
                  P                  R4      pV'       g   RRRR/#  ^ R	IHpH	pH
p VR
8X  d   TMTp\        P                  ! \        P                  \        P                  4      pVP                  R4       VP                  V4       RVP                   R^RVRV/p	VP#                  W4       VP%                  V4      p
VP'                  4        V
P                  R4      VP(                  8X  d   V
P                  RRR/4      # V
P                  R4      VP*                  8X  d2   V
P                  R/ 4      pRRRVP                  R\-        V4      4      /# RRRRV
P                  R4       2/#   \.         d   pRRR\-        T4      /u Rp?# Rp?ii ; i)z
Send a worker management message to the dirty arbiter.

Args:
    operation: "add" or "remove"
    count: Number of workers to add/remove

Returns:
    Dictionary with result or error
Nr;   socket_pathGUNICORN_DIRTY_SOCKETr   Fr   z%Cannot find dirty arbiter socket path)DirtyProtocolMANAGE_OP_ADDMANAGE_OP_REMOVEr   g      $@rj   idopr&   resultTmessagezUnexpected response type: )rD   r   r;   rC   r   environrH   gunicorn.dirty.protocolr   r   r   r   r   SOCK_STREAM
settimeoutconnectMSG_TYPE_MANAGEwrite_messageread_messagecloseMSG_TYPE_RESPONSEMSG_TYPE_ERRORre   r   )r   r   r&   dirty_socket_pathr   r   r   r   r   requestresponser   r   s   &&&          r   r   $CommandHandlers._send_manage_message^  s    !4<<11dll6P6P6P '**M4! ! "

/F G 5@ 
*	  #,u"4:JB==1C1CDDOOD!LL*+ 55ab	G ''6 %11$7HJJL||F#}'F'FF||Hy$.?@@f%)E)EE Wb1uUYYy#e*=  u9(,,v:N9OP 
  	5Q 	s,   C#G 6AG G H*G>8H>Hc                    < V ^8  d   QhRS[ /# r   r   )r   r   s   "r   r   r     s     	' 	' 	'r   c                |    \         P                  ! V P                  P                  \        P
                  4       RR/# )zV
Trigger graceful reload (equivalent to SIGHUP).

Returns:
    Dictionary with status
status	reloading)r   r   r   r   r   SIGHUPr   s   &r   r]   CommandHandlers.reload  s+     	  &--0+&&r   c                    < V ^8  d   QhRS[ /# r   r   )r   r   s   "r   r   r     s     ' ' 'r   c                |    \         P                  ! V P                  P                  \        P
                  4       RR/# )zP
Reopen log files (equivalent to SIGUSR1).

Returns:
    Dictionary with status
r   	reopening)r   r   r   r   r   SIGUSR1r   s   &r   reopenCommandHandlers.reopen  s+     	  &..1+&&r   c                &   < V ^8  d   QhRS[ RS[/# )r   moder   )re   r   )r   r   s   "r   r   r     s     9 9S 9$ 9r   c                   VR8X  d;   \         P                  ! V P                  P                  \        P
                  4       M9\         P                  ! V P                  P                  \        P                  4       RRRV/# )zs
Initiate shutdown.

Args:
    mode: "graceful" (SIGTERM) or "quick" (SIGINT)

Returns:
    Dictionary with status
quickr   shutting_downr   )r   r   r   r   r   SIGINTr   )r   r   s   &&r   shutdownCommandHandlers.shutdown  sR     7?GGDLL$$fmm4GGDLL$$fnn5/6488r   c                    < V ^8  d   QhRS[ /# r   r   )r   r   s   "r   r   r     s     9
 9
$ 9
r   c                   \         P                  ! 4       pRV P                  P                  RRRR/p. pV P                  P                  P                  4        Fa  w  rE VP                  P                  4       p\        W,
          ^4      pVP                  RVRRRVP                  R	VP                  R
V/4       Kc  	  VP                  R R7       Rp. p	V P                  P                  '       d-   RV P                  P                  RRRR/pV P!                  4       p	RVRVR\#        V4      RVRV	R\#        V	4      /#   \        \        3 d    Rp Li ; i)z
Return overview of all processes (arbiter, web workers, dirty arbiter, dirty workers).

Returns:
    Dictionary with complete process hierarchy
r   rj   r   rolemasterNwebr   r   r   c                     V R ,          # r   r   r   s   &r   r!   *CommandHandlers.show_all.<locals>.<lambda>  s    qxr   r#   r;   zdirty masterweb_workersweb_worker_countr^   dirty_worker_count)r'   r(   r   r   r)   r*   r+   r,   r-   r.   r/   r0   r   r   r1   rB   _query_dirty_workersr2   )
r   r3   arbiter_infor   r   r4   r,   r   dirty_arbiter_infor^   s
   &         r   show_allCommandHandlers.show_all  sf    nn 4<<##IH
 <<//557KC&$jj446!&s'8!!< svzz&-- .   8  	/0 "<<)))t||55" !557M |;K 0/] #m"4
 	
9 Z( &!%&s   ,D<<EEc                    < V ^8  d   QhRS[ /# r   )rF   )r   r   s   "r   r   r     s     + +d +r   c                   Rp\        V P                  R4      '       d>   V P                  P                  '       d"   \        V P                  P                  RR4      pV'       g    \        P
                  P                  R4      pV'       g   . #  ^ RIHp \        P                  ! \        P                  \        P                  4      pVP                  R4       VP                  V4       RVP                  RR	/pVP                  W44       VP!                  V4      pVP#                  4        VP                  R4      VP$                  8X  d%   VP                  R
/ 4      pVP                  R. 4      #  . #   \&         d     . # i ; i)z
Query the dirty arbiter for worker information.

Connects to the dirty arbiter socket and sends a status request.

Returns:
    List of dirty worker info dicts, or empty list on error
Nr;   r   r   )r   g       @rj   r   zctl-status-1r   r%   )rD   r   r;   rC   r   r   rH   r   r   r   r   r   r   r   MSG_TYPE_STATUSr   r   r   r   r   )r   r   r   r   r   r   r   s   &      r   r   $CommandHandlers._query_dirty_workers  s@    !4<<11dll6P6P6P '(B(BMSW X  "

/F G I	===1C1CDDOOC LL*+ 55nG ''6 %11$7HJJL||F#}'F'FF!h3zz)R00 G 	  			s   C E2 2F Fc                    < V ^8  d   QhRS[ /# r   r   )r   r   s   "r   r   r   1  s     & &d &r   c                J    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/pRV/# ) z\
Return list of available commands.

Returns:
    Dictionary with commands and descriptions
zshow allz8Show all processes (arbiter, web workers, dirty workers)zshow workersz#List HTTP workers with their statusz
show dirtyzList dirty workers and appszshow configz$Show current effective configurationz
show statszShow server statisticszshow listenerszShow bound socketszworker add [N]zSpawn N workers (default 1)zworker remove [N]zRemove N workers (default 1)zworker kill <PID>z$Gracefully terminate specific workerzdirty add [N]z!Spawn N dirty workers (default 1)zdirty remove [N]z"Remove N dirty workers (default 1)r]   zGraceful reload (HUP)r   zReopen log files (USR1)zshutdown [graceful|quick]zShutdown server (TERM/INT)helpzShow this help messagecommandsr   )r   r	  s   & r   r  CommandHandlers.help1  sr     RA7A22;!?!G@ D-/')E,
" H%%r   r   N)   )graceful)__name__
__module____qualname____firstlineno____doc__r	   r5   rK   rn   r|   r   r   r   r   r   r   r   r]   r   r   r   r   r  __static_attributes____classdictcell__)r   s   @r   r   r      s     !; !;F:
 :
x! !F
 
>A A@
 
.
 
8 <7 7*: :*C CJ	' 	'' '9 9"9
 9
v+ +Z& &r   r   )r  r   r   r   r'   r   r   r   r   <module>r     s$   
 
   x& x&r   