How do I stop a Supervisord process without killing the program it's controlling? -
i using supervisord continually run indexing programs. each time indexer run, grabs set of documents, indexes them, ends. supervisord process spawn of same indexer program, , indexer grab new set of documents index.
sometimes need stop supervisord process running these indexer programs. when do, however, kills indexer program in middle of work.
what i'd stop supervisord process indexer program running execute completion, supervisord process not spawn indexer.
here supervisord.conf settings process:
; triggering indexers ; [program:indexer] command=php /data/app/index_company.php process_name=%(program_name)s_%(process_num)d redirect_stderr=true stdout_capture_maxbytes=10mb stdout_logfile_backups=0 numprocs=5 startsecs=0 autostart=false autorestart=true [group:indexers] programs=indexer
supervisord
emit sigterm
signal when stop requested. child can catch , process signal (the stopsignal
configuration can change signal sent).
since you're using php, pcntl_signal
seems way go. can't guess how master works i'll assume it's infinite loop, single-threaded. here's primitive example:
<?php $stop_requested = false; pcntl_signal( sigterm, function() { global $stop_requested; $stop_requested = true; } ); while ( true ) { do_work(); if ( $stop_requested ) break; } ?>
now, when try stop process not terminated. however, still stop after 10 seconds. why?
because stopwaitsecs
set 10 seconds default. time supervisord
wait until sending sigkill
kill process. setting know work well, 600 seconds allow indexer finish work before shutting down.
[program:indexer] command=php index.php stopwaitsecs=600
the above should enough allow indexer gracefully stop. there's @ least 1 issue long waiting times, though: supervisorctl
keep on waiting , not process further commands until process stops. can run instance. not sure happens webclient (might keep on loading , expecting response).
while above approach work fine you, should revise setup , not have supervisord
hang around long waiting shutdown happen. indexers should stop can, not fetching more work, flushing results, or whatever doing. smaller chunks of useful work make sure exit within reasonable amount of time.
hope helps. let me know how goes.
Comments
Post a Comment