[Twisted-Python] Recommended daemon monitoring tools for ubuntu

Louis D. Burr ldanielburr at me.com
Thu May 16 12:14:38 MDT 2013



On May 16, 2013, at 12:34 PM, Justin Venus <justin.venus at gmail.com> wrote:

> IMO monit is pretty easy to setup and probably your best bet.  However you could get puppet, chef, or cfengine to start processes for you.  If you are feeling adventurous, you could set up something like apache mesos to keep your tasks running.
>
> Justin Venus
> On May 16, 2013 10:27 AM, "Jonathan Vanasco" <twisted-python at 2xlp.com> wrote:
>
>     Hi,
>
>     i'm running a twisted daemon on ubuntu
>
>     It seems to get shut down by the system periodically.  Logs show that the kernel (or something) kills it for taking up too much memory.  I definitely have coding issues in there that i'm working on to address this.
>
>     Does anyone have a suggestion for tools I can easily use on ubuntu to monitor and restart if needed ?  I haven't had to do something like this in 5 years, and back then it was a hassle to get monit or supervisord working.
>
>     thanks
>
>     /jonathan
>     _______________________________________________
>     Twisted-Python mailing list
>     Twisted-Python at twistedmatrix.com
>     http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
 

Another simple option is to use twisted's own procmon.ProcessMonitor to launch your twistd daemon.  You can use it "out of the box", or implement your own service based upon it, e.g.,


from twisted.python import usage
from twisted.runner import procmon



class Options(usage.Options):
    synopsis = '[mymonitor options] commandline'

    optParameters = (
        (
            'threshold',
            't',
            1,
            'How many seconds a process has to run before it is considered to have died instantly.',
            float
        ),
        (
            'killtime',
            'k',
            5,
            'How many seconds a process being killed has to get its affairs in order before it gets killed with an unmaskable signal.',
            float
        ),
        (
            'minrestartdelay',
            'm',
            1,
            'The minimum number of seconds to wait before attempting to restart a process.',
            float
        ),
        (
            'maxrestartdelay',
            'M',
            3600,
            'The maximum number of seconds to wait before attempting to restart a process.',
            float
        )
    )

    optFlags = ()


    longdesc = """Blah blah blah"""

    def parseArgs(self, *args):
        """
        Grab the command line that is going to be started and monitored
        """
        self['args'] = args


    def postOptions(self):
        """
        Check for dependencies.
        """
        if len(self['args']) < 1:
            raise usage.UsageError('Please specify a process commandline')


def makeService(config):
    from twisted.internet import reactor

    myMonitorService = procmon.ProcessMonitor(reactor)

    myMonitorService.threshold = config['threshold']
    myMonitorService.killTime = config['killtime']
    myMonitorService.minRestartDelay = config['minrestartdelay']
    myMonitorService.maxRestartDelay = config['maxrestartdelay']
    myMonitorService.addProcess(
        'MyTwistedServiceThatSometimesBlowsUp',
        config['args'],
        uid=None,
        gid=None,
        env={}
    )
    return myMonitorService


Hope this helps,

Daniel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20130516/f63a03ce/attachment.html>


More information about the Twisted-Python mailing list