@@ -256,7 +256,10 @@ def handle_hup(self):
256256 - Gracefully shutdown the old worker processes
257257 """
258258 self .log .info ("Hang up: %s" , self .master_name )
259+ systemd .sd_notify ("RELOADING=1\n STATUS=Gunicorn arbiter reloading.." , self .log )
259260 self .reload ()
261+ # possibly premature, newly launched workers might have failed
262+ systemd .sd_notify ("READY=1\n STATUS=Gunicorn arbiter reloaded" , self .log )
260263
261264 def handle_term (self ):
262265 "SIGTERM handling"
@@ -332,6 +335,8 @@ def maybe_promote_master(self):
332335 self .pidfile .rename (self .cfg .pidfile )
333336 # reset proctitle
334337 util ._setproctitle ("master [%s]" % self .proc_name )
338+ # MAINPID does not change here, it was already set on fork
339+ systemd .sd_notify ("READY=1\n MAINPID=%d\n STATUS=Gunicorn arbiter promoted" % (os .getpid (), ), self .log )
335340
336341 def wakeup (self ):
337342 """\
@@ -437,6 +442,9 @@ def reexec(self):
437442 os .chdir (self .START_CTX ['cwd' ])
438443
439444 # exec the process using the original environment
445+ self .log .debug ("exe=%r argv=%r" % (self .START_CTX [0 ], self .START_CTX ['args' ]))
446+ # let systemd know are are in control
447+ systemd .sd_notify ("READY=1\n MAINPID=%d\n STATUS=Gunicorn arbiter re-exec" % (master_pid , ), self .log )
440448 os .execve (self .START_CTX [0 ], self .START_CTX ['args' ], environ )
441449
442450 def reload (self ):
@@ -527,6 +535,8 @@ def reap_workers(self):
527535 if self .reexec_pid == wpid :
528536 self .reexec_pid = 0
529537 self .log .info ("Master exited before promotion." )
538+ # let systemd know we are (back) in control
539+ systemd .sd_notify ("READY=1\n MAINPID=%d\n STATUS=Gunicorn arbiter re-exec aborted" % (os .getpid (), ), self .log )
530540 continue
531541 else :
532542 worker = self .WORKERS .pop (wpid , None )
0 commit comments