Successfully exit of salt-api child processes when SIGTERM.

So far, salt-api handles connection creating child processes, but this new
processes are not handling the SIGTERM signal, so when `systemctl stop salt-api`
is called the salt-api service is going to be KILLED by `TimeoutStopSec=3`
option of salt-api service. This causes that salt-api looks as FAILED for systemd
even if we perform a manually stop.
FAILED systemd services has different behavior when `systemd try-restart` is called
so we may have troubles i.e. when updating salt-api package.

This commit enables SIGTERM handling for salt-api child processes to perform a
successfully exit after SIGTERM.
This commit is contained in:
Pablo Suárez Hernández 2016-12-14 11:34:43 +00:00
parent 70f7d22ad6
commit ee6eae9855

View file

@ -424,7 +424,9 @@ import itertools
import functools
import logging
import json
import os
import StringIO
import signal
import tarfile
import time
from multiprocessing import Process, Pipe
@ -2182,6 +2184,12 @@ class WebsocketEndpoint(object):
listen=True)
stream = event.iter_events(full=True, auto_reconnect=True)
SaltInfo = event_processor.SaltInfo(handler)
def signal_handler(signal, frame):
os._exit(0)
signal.signal(signal.SIGTERM, signal_handler)
while True:
data = next(stream)
if data: