1 # -*- test-case-name: twisted.runner.test.test_procmontap -*-
2 # Copyright (c) Twisted Matrix Laboratories.
3 # See LICENSE for details.
6 Support for creating a service which runs a process monitor.
9 from twisted.python import usage
10 from twisted.runner.procmon import ProcessMonitor
13 class Options(usage.Options):
15 Define the options accepted by the I{twistd procmon} plugin.
18 synopsis = "[procmon options] commandline"
20 optParameters = [["threshold", "t", 1, "How long a process has to live "
21 "before the death is considered instant, in seconds.",
23 ["killtime", "k", 5, "How long a process being killed "
24 "has to get its affairs in order before it gets killed "
25 "with an unmaskable signal.",
27 ["minrestartdelay", "m", 1, "The minimum time (in "
28 "seconds) to wait before attempting to restart a "
30 ["maxrestartdelay", "M", 3600, "The maximum time (in "
31 "seconds) to wait before attempting to restart a "
38 procmon runs processes, monitors their progress, and restarts them when they
41 procmon will not attempt to restart a process that appears to die instantly;
42 with each "instant" death (less than 1 second, by default), it will delay
43 approximately twice as long before restarting it. A successful run will reset
46 Eg twistd procmon sleep 10"""
48 def parseArgs(self, *args):
50 Grab the command line that is going to be started and monitored
55 def postOptions(self):
57 Check for dependencies.
59 if len(self["args"]) < 1:
60 raise usage.UsageError("Please specify a process commandline")
64 def makeService(config):
67 s.threshold = config["threshold"]
68 s.killTime = config["killtime"]
69 s.minRestartDelay = config["minrestartdelay"]
70 s.maxRestartDelay = config["maxrestartdelay"]
72 s.addProcess(" ".join(config["args"]), config["args"])