index.rst 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. :orphan:
  2. .. _ext-processes:
  3. ===============================
  4. Running Custom Master Processes
  5. ===============================
  6. .. note::
  7. :ref:`Salt engines <engines>` are a new feature in 2015.8.0 that let you run
  8. custom processes on the Salt master and on Salt minions. Salt engines provide
  9. more functionality than ``ext_processes`` by accepting arguments, and by
  10. providing access to Salt config, execution modules, and runners.
  11. In addition to the processes that the Salt master automatically spawns,
  12. it is possible to configure it to start additional custom processes.
  13. This is useful if a dedicated process is needed that should run throughout
  14. the life of the Salt master. For periodic independent tasks, a
  15. :ref:`scheduled runner <scheduling-jobs>` may be more appropriate.
  16. Processes started in this way will be restarted if they die and will be
  17. killed when the Salt master is shut down.
  18. Example Configuration
  19. =====================
  20. Processes are declared in the master config file with the `ext_processes`
  21. option. Processes will be started in the order they are declared.
  22. .. code-block:: yaml
  23. ext_processes:
  24. - mymodule.TestProcess
  25. - mymodule.AnotherProcess
  26. Example Process Class
  27. =====================
  28. .. code-block:: python
  29. # Import python libs
  30. import time
  31. import logging
  32. from multiprocessing import Process
  33. # Import Salt libs
  34. from salt.utils.event import SaltEvent
  35. log = logging.getLogger(__name__)
  36. class TestProcess(Process):
  37. def __init__(self, opts):
  38. Process.__init__(self)
  39. self.opts = opts
  40. def run(self):
  41. self.event = SaltEvent('master', self.opts['sock_dir'])
  42. i = 0
  43. while True:
  44. self.event.fire_event({'iteration': i}, 'ext_processes/test{0}')
  45. time.sleep(60)