1.8 KiB
- orphan
Running Custom Master Processes
Note
Salt engines <engines>
are a new feature in
2015.8.0 that let you run custom processes on the Salt master and on
Salt minions. Salt engines provide more functionality than
ext_processes
by accepting arguments, and by providing
access to Salt config, execution modules, and runners.
In addition to the processes that the Salt master automatically spawns, it is possible to configure it to start additional custom processes.
This is useful if a dedicated process is needed that should run
throughout the life of the Salt master. For periodic independent tasks,
a scheduled runner <scheduling-jobs>
may be more
appropriate.
Processes started in this way will be restarted if they die and will be killed when the Salt master is shut down.
Example Configuration
Processes are declared in the master config file with the ext_processes option. Processes will be started in the order they are declared.
ext_processes:
- mymodule.TestProcess
- mymodule.AnotherProcess
Example Process Class
# Import python libs
import time
import logging
from multiprocessing import Process
# Import Salt libs
from salt.utils.event import SaltEvent
= logging.getLogger(__name__)
log
class TestProcess(Process):
def __init__(self, opts):
__init__(self)
Process.self.opts = opts
def run(self):
self.event = SaltEvent("master", self.opts["sock_dir"])
= 0
i
while True:
self.event.fire_event({"iteration": i}, "ext_processes/test{0}")
60) time.sleep(