Чтобы мягко перезапустить supervisord (без убивания процесса), набираем
sudo supervisorctl reread sudo supervisorctl update
sudo supervisorctl reread sudo supervisorctl update
# supervisorctl api-test-data RUNNING pid 22443, uptime 1 day, 16:52:01 api-test-empty FATAL Exited too quickly (process log may have details) auth-service RUNNING pid 22444, uptime 1 day, 16:52:01
supervisor> start api-test-empty api-test-empty: started supervisor> status api-test-data RUNNING pid 22443, uptime 1 day, 16:52:29 api-test-empty RUNNING pid 27360, uptime 0:00:13 auth-service RUNNING pid 22444, uptime 1 day, 16:52:29 supervisor>
finger finger/__init__.py finger/finger.py MANIFEST.in setup.py twisted twisted/plugins twisted/plugins/finger_plugin.py
# ==== twisted/plugins/finger_plugin.py ==== # - Zope modules - from zope.interface import implements # - Twisted modules - from twisted.python import usage from twisted.application.service import IServiceMaker from twisted.plugin import IPlugin # - Finger modules - from finger import finger class Options(usage.Options): synopsis = "[options]" longdesc = "Make a finger server." optParameters = [ ['file', 'f', '/etc/users'], ['templates', 't', '/usr/share/finger/templates'], ['ircnick', 'n', 'fingerbot'], ['ircserver', None, 'irc.freenode.net'], ['pbport', 'p', 8889], ] optFlags = [['ssl', 's']] class MyServiceMaker(object): implements(IServiceMaker, IPlugin) tapname = "finger" description = "Finger server." options = Options def makeService(self, config): return finger.makeService(config) serviceMaker = MyServiceMaker()
# ==== twisted/plugins/finger_plugin.py ==== '''setup.py for finger. This is an extension of the Twisted finger tutorial demonstrating how to package the Twisted application as an installable Python package and twistd plugin (consider it "Step 12" if you like). Uses twisted.python.dist.setup() to make this package installable as a Twisted Application Plugin. After installation the application should be manageable as a twistd command. For example, to start it in the foreground enter: $ twistd -n finger To view the options for finger enter: $ twistd finger --help ''' __author__ = 'Chris Miles' import sys try: import twisted except ImportError: raise SystemExit("twisted not found. Make sure you " "have installed the Twisted core package.") from distutils.core import setup def refresh_plugin_cache(): from twisted.plugin import IPlugin, getPlugins list(getPlugins(IPlugin)) if __name__ == '__main__': if sys.version_info[:2] >= (2, 4): extraMeta = dict( classifiers=[ "Development Status :: 4 - Beta", "Environment :: No Input/Output (Daemon)", "Programming Language :: Python", ]) else: extraMeta = {} setup( name="finger", version='0.1', description="Finger server.", author=__author__, author_email="you@email.address", url="http://twistedmatrix.com/projects/core/documentation/howto/tutorial/index.html", packages=[ "finger", "twisted.plugins", ], package_data={ 'twisted': ['plugins/finger_plugin.py'], }, **extraMeta) refresh_plugin_cache()
$ python setup.py install
$ twistd --help Usage: twistd [options] ... Commands: athena-widget Create a service which starts a NevowSite with a single page with a single widget. ftp An FTP server. telnet A simple, telnet-based remote debugging service. socks A SOCKSv4 proxy service. manhole-old An interactive remote debugger service. portforward A simple port-forwarder. web A general-purpose web server which can serve from a filesystem or application resource. inetd An inetd(8) replacement. vencoderd Locayta Media Farm vencoderd video encoding server. news A news server. words A modern words server toc An AIM TOC service. finger Finger server. dns A domain name server. mail An email service manhole An interactive remote debugger service accessible via telnet and ssh and providing syntax coloring and basic line editing functionality. conch A Conch SSH service.
$ twistd finger --help
Usage: twistd [options] finger [options] Options: -s, --ssl -f, --file= [default: /etc/users] -t, --templates= [default: /usr/share/finger/templates] -n, --ircnick= [default: fingerbot] --ircserver= [default: irc.freenode.net] -p, --pbport= [default: 8889] --version --help Display this help and exit. Make a finger server.
$ sudo twistd -n finger --file=users 2007/12/23 22:12 +1100 [-] Log opened. 2007/12/23 22:12 +1100 [-] twistd 2.5.0 (/Library/Frameworks/Python.framework/ Versions/2.5/Resources/Python.app/Contents/MacOS/Python 2.5.0) starting up 2007/12/23 22:12 +1100 [-] reactor class:2007/12/23 22:12 +1100 [-] finger.finger.FingerFactoryFromService starting on 79 2007/12/23 22:12 +1100 [-] Starting factory 2007/12/23 22:12 +1100 [-] twisted.web.server.Site starting on 8000 2007/12/23 22:12 +1100 [-] Starting factory 2007/12/23 22:12 +1100 [-] twisted.spread.pb.PBServerFactory starting on 8889 2007/12/23 22:12 +1100 [-] Starting factory 2007/12/23 22:12 +1100 [-] Starting factory
#!/usr/bin/python import sys import src.daemon import procname class YourServer(twisted.web.server.Site): pass class YourDaemon(Daemon): name = 'yourserverd' site = None server = None #-------------------------------------------------------------------------- def __init__(self): self.server = YourServer() Daemon.__init__(self, pidfile='/var/run/%s.pid' % (self.name.lower()) ) procname.setprocname(self.name) #-------------------------------------------------------------------------- def run(self): self.server = YourServer() reactor.listenTCP(self.server.port, self.server) reactor.run() if __name__ == '__main__': daemon = YourDaemon() daemon.processAction(sys.argv)