Move sigterm_method to zuul.conf

Instead of using an environment variable for this particular
setting, do what we do for every other aspect of Zuul behavior:
use a setting in zuul.conf.

Change-Id: I5c075dce5b6ad23adc863252af67d7ee7ad0d4d5
This commit is contained in:
James E. Blair 2021-08-12 14:22:39 -07:00
parent 7256c52c34
commit d80555a453
3 changed files with 26 additions and 9 deletions

View File

@ -865,6 +865,21 @@ The following sections of ``zuul.conf`` are used by the executor:
perform merge operations for any events. The executor will still perform
the merge operations required for the build they are executing.
.. attr:: sigterm_method
:default: graceful
Determines how the executor responds to a ``SIGTERM`` signal.
.. value:: graceful
Stop accepting new jobs and wait for all running jobs to
complete before exiting.
.. value:: stop
Abort all running jobs and exit as soon as possible.
.. attr:: keystore
.. attr:: password
@ -929,9 +944,7 @@ running on the stopped executor will be rescheduled on other executors.
The executor normally responds to a ``SIGTERM`` signal in the same way
as the ``graceful`` command, however you can change this behavior to match
``stop`` by setting the environment variable
``ZUUL_EXECUTOR_SIGTERM_METHOD`` to ``stop`` (the default is
``graceful``).
``stop`` with the :attr:`executor.sigterm_method` setting.
To enable or disable running Ansible in verbose mode (with the
``-vvv`` argument to ansible-playbook) run ``zuul-executor verbose``

View File

@ -1,13 +1,13 @@
---
features:
- |
The executor now honors the ``ZUUL_EXECUTOR_SIGTERM_METHOD``
environment variable to determine whether ``SIGTERM`` should be
The executor now honors the :attr:`executor.sigterm_method`
configuration file setting to determine whether ``SIGTERM`` should be
equivalent to the ``graceful`` command (the default) or the
``stop`` command.
upgrade:
- |
The default behavior when an executor receives SIGTERM has been
changed from immediately stopping jobs to gracefully waiting for
them to finish. Set the ``ZUUL_EXECUTOR_SIGTERM_METHOD``
environment variable to ``stop`` to preserve the old behavior.
them to finish. Set the :attr:`executor.sigterm_method`
configuration file setting to ``stop`` to preserve the old behavior.

View File

@ -44,14 +44,18 @@ class Executor(zuul.cmd.ZuulDaemonApp):
self.args.nodaemon = True
def exit_handler(self, signum, frame):
graceful = os.environ.get('ZUUL_EXECUTOR_SIGTERM_METHOD', 'graceful')
if self.config.has_option('executor', 'sigterm_method'):
graceful = self.config.get('executor', 'sigterm_method')
else:
graceful = 'graceful'
if graceful.lower() == 'graceful':
self.executor.graceful()
elif graceful.lower() == 'stop':
self.executor.stop()
else:
self.log.error("Unknown value for ZUUL_EXECUTOR_SIGTERM_METHOD:"
self.log.error("Unknown value for executor.sigterm_method:"
f"'{graceful}'. Expected 'graceful' or 'stop'")
self.executor.graceful()
def start_log_streamer(self):
pipe_read, pipe_write = os.pipe()