def salt_minion(): ''' Start the salt minion. ''' if '' in sys.path: sys.path.remove('') if '--disable-keepalive' in sys.argv: sys.argv.remove('--disable-keepalive') minion = salt.Minion() minion.start() return if '-d' in sys.argv or '--daemon' in sys.argv: # disable daemonize on sub processes if '-d' in sys.argv: sys.argv.remove('-d') if '--daemon' in sys.argv: sys.argv.remove('--daemon') # daemonize current process salt.utils.daemonize() # keep one minion subprocess running while True: try: queue = multiprocessing.Queue() except Exception: # This breaks in containers minion = salt.Minion() minion.start() return process = multiprocessing.Process(target=minion_process, args=(queue, )) process.start() try: process.join() try: restart_delay = queue.get(block=False) except Exception: if process.exitcode == 0: # Minion process ended naturally, Ctrl+C or --version break restart_delay = 60 if restart_delay == 0: # Minion process ended naturally, Ctrl+C, --version, etc. break # delay restart to reduce flooding and allow network resources to close time.sleep(restart_delay) except KeyboardInterrupt: break # need to reset logging because new minion objects # cause extra log handlers to accumulate rlogger = logging.getLogger() for handler in rlogger.handlers: rlogger.removeHandler(handler) logging.basicConfig()
def start(self): self.runflag=True self.log("Starting the Salt Minion") minion = salt.Minion() minion.start() while self.runflag: pass
def salt_minion(): ''' Kick off a salt minion daemon. ''' if '' in sys.path: sys.path.remove('') minion = salt.Minion() minion.start()
def salt_minion(): ''' Start the salt minion. ''' if '' in sys.path: sys.path.remove('') minion = salt.Minion() minion.start()
def minion_process(queue): ''' Start a minion process ''' # salt_minion spawns this function in a new process def suicide_when_without_parent(parent_pid): ''' Have the minion suicide if the parent process is gone NOTE: there is a small race issue where the parent PID could be replace with another process with the same PID! ''' while True: time.sleep(5) try: # check pid alive (Unix only trick!) os.kill(parent_pid, 0) except OSError: sys.exit(999) if not salt.utils.is_windows(): thread = threading.Thread(target=suicide_when_without_parent, args=(os.getppid(), )) thread.start() restart = False minion = None try: minion = salt.Minion() minion.start() except (Exception, SaltClientError, SaltReqTimeoutError, SaltSystemExit) as exc: log.error(exc) restart = True except SystemExit as exc: restart = False if restart is True: log.warn('** Restarting minion **') delay = 60 if minion is not None: if hasattr(minion, 'config'): delay = minion.config.get('random_reauth_delay', 60) random_delay = randint(1, delay) log.info( 'Sleeping random_reauth_delay of {0} seconds'.format(random_delay)) # preform delay after minion resources have been cleaned queue.put(random_delay) else: queue.put(0)
def salt_minion(): ''' Kick off a salt minion daemon. ''' if '' in sys.path: sys.path.remove('') reconnect = True while reconnect: reconnect = False minion = salt.Minion() ret = minion.start() if ret == 'reconnect': del minion minion = None # give extra time for resources like ZMQ to close. time.sleep(10) reconnect = True
def minion_run(self, cleanup_protecteds): minion = salt.Minion() # daemonizes here minion.call(cleanup_protecteds=cleanup_protecteds ) # caller minion.call_in uses caller.flo
def salt_minion(): ''' Kick off a salt minion daemon. ''' minion = salt.Minion() minion.start()