mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 08:58:59 +00:00
Handle SIGINT and SIGTERM and actually exit the process
This commit is contained in:
parent
588285981b
commit
33336a799b
@ -85,6 +85,8 @@ import salt.utils.cache
|
||||
import salt.utils.dicttrim
|
||||
import salt.utils.process
|
||||
import salt.utils.zeromq
|
||||
import salt.log.setup
|
||||
import salt.defaults.exitcodes
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@ -946,7 +948,11 @@ class EventReturn(multiprocessing.Process):
|
||||
self.stop = False
|
||||
|
||||
def sig_stop(self, signum, frame):
|
||||
self.stop = True # tell it to stop
|
||||
# Flush and terminate
|
||||
if self.event_queue:
|
||||
self.flush_events()
|
||||
self.stop = True
|
||||
exit(salt.defaults.exitcodes.EX_GENERIC)
|
||||
|
||||
def flush_events(self):
|
||||
event_return = '{0}.event_return'.format(
|
||||
@ -971,8 +977,9 @@ class EventReturn(multiprocessing.Process):
|
||||
'''
|
||||
Spin up the multiprocess event returner
|
||||
'''
|
||||
# Properly exit if a SIGTERM is signalled
|
||||
# Properly exit if a SIGTERM/SIGINT is signalled
|
||||
signal.signal(signal.SIGTERM, self.sig_stop)
|
||||
signal.signal(signal.SIGINT, self.sig_stop)
|
||||
|
||||
salt.utils.appendproctitle(self.__class__.__name__)
|
||||
self.event = get_event('master', opts=self.opts, listen=True)
|
||||
@ -988,10 +995,6 @@ class EventReturn(multiprocessing.Process):
|
||||
self.flush_events()
|
||||
if self.stop:
|
||||
break
|
||||
except KeyboardInterrupt:
|
||||
if self.event_queue:
|
||||
self.flush_events()
|
||||
self.stop = True
|
||||
except zmq.error.ZMQError as exc:
|
||||
if exc.errno != errno.EINTR: # Outside interrupt is a normal shutdown case
|
||||
raise
|
||||
|
Loading…
Reference in New Issue
Block a user