Download - Troubleshooting Plone
Introducing a New Product
Troubleshooting Plone
Ricardo Alves
Plone Conference 2009 - Budapest
What can go wrong?
Main Issues
Site errors and broken objects
Instance not responding
Server IO errors
Unauthorized / security errors
Site Errors
Analyzing the traceback at error_log:http://mysite/plonesite/error_log/manage_main
Site Errors
Analyzing Zope's event log:INSTANCE_HOME/logs/event.log
Module zope.tal.talinterpreter, line 346, in interpret Module zope.tal.talinterpreter, line 745, in do_insertStructure_tal Module zope.tales.tales, line 696, in evaluate - URL: file:/Users/rsa/eurotux/udp/iporto/bundle/plone/CMFPlone/skins/plone_content/newsitem_view.pt - Line 41, Column 15 - Expression: - Names: {'container': , 'context': , 'default': , 'here': , 'loop': {}, 'nothing': None, 'options': {'args': ()}, 'repeat': , 'request': , 'root': , 'template': , 'traverse_subpath': [], 'user': } Module Products.PageTemplates.ZRPythonExpr, line 49, in __call__ - __traceback_info__: here.tag(scale='mini', css_class='newsImage') Module PythonExpr, line 1, in Module Products.ATContentTypes.content.newsitem, line 130, in tagAttributeError: 'NoneType' object has no attribute 'tag'
2009-10-28T16:43:46 WARNING LinguaPlone The thread number -1337921536 doesn't have an associated request object.------2009-10-28T16:45:00 INFO SignalHandler Caught signal SIGINT------2009-10-28T16:45:00 INFO Z2 Shutting down------2009-10-28T16:45:21 INFO ZServer HTTP server started at Wed Oct 28 16:45:21 2009 Hostname: 0.0.0.0 Port: 9095------2009-10-28T16:45:23 INFO Marshall libxml2-python not available. Unable to register libxml2 based marshallers.------2009-10-28T16:45:27 INFO ZEO.ClientStorage (4478) ClientStorage (pid=4478) created RW/normal for storage: '1'------2009-10-28T16:45:27 INFO ZEO.cache created temporary cache file ''------2009-10-28T16:45:27 INFO ZEO.ClientStorage (4478) Testing connection
------2009-10-28T16:45:27 INFO ZEO.zrpc.Connection(C) (127.0.0.1:9096) received handshake 'Z303'
Logging level
Analyzing Zope's event log:INSTANCE_HOME/etc/zope.conf
level info path $INSTANCE/log/event.log level info # "CRITICAL", 'ERROR", WARN", "INFO",# "DEBUG", and "ALL"
level WARN path $INSTANCE/log/access.log format %(message)s
Logging yourself
Logging to event log from product code:
>>> import logging
>>> logger = logging.getLogger('My package')
>>> logger.log(logging.INFO, 'My message')
>>> context.plone_log('My message')
From skin layers (as Plone):
System logs
$ tail -f /var/log/system.log
Specially if connecting with other applications (mail server, etc)
$ tail -f /var/log/messages
$ tail -f /var/log/system.log
Instance not responding
Make sure that Zope is failing:
$ telnet localhost 80 Trying ::1...telnet: connect to address ::1: Connection refusedTrying 127.0.0.1...Connected to localhost.Escape character is '^]'.GET /plone HTTP/1.1
HTTP/1.1 200 OKServer: Zope/(Zope 2.10.4-final, python 2.4.4, darwin) ZServer/1.1 Plone/3.1.7Date: Wed, 28 Oct 2009 19:13:49 GMTContent-Length: 20541Expires: Sat, 1 Jan 2000 00:00:00 GMTContent-Type: text/html;charset=utf-8Content-Language: en
...
Instance not responding
$ telnet localhost 80 Trying ::1...telnet: connect to address ::1: Connection refusedTrying 127.0.0.1...Connected to localhost.Escape character is '^]'.GET /plone HTTP/1.1
HTTP/1.1 404 Not FoundServer: Zope/(Zope 2.10.4-final, python 2.4.4, darwin) ZServer/1.1 Plone/3.1.7Date: Wed, 28 Oct 2009 19:16:57 GMTBobo-Exception-Line: 100Content-Length: 812Bobo-Exception-Value: See the server error log for detailsContent-Type: text/html; charset=iso-8859-15Bobo-Exception-Type: NotFoundBobo-Exception-File: BaseRequest.py
Zope
...
Instance not responding
Make sure that ZEO is responding:
$ telnet localhost 81Trying ::1...telnet: connect to address ::1: Connection refusedTrying 127.0.0.1...Connected to localhost.Escape character is '^]'.Z303
Instance not responding
Start Zope in foreground:
$ INSTANCE_HOME/bin/zopectl fg
Start Zope in debug mode:INSTANCE_HOME/etc/zope.conf:
# Directive: debug-mode...## Setting this to 'off' when Zope is in a production environment is# encouraged, as it speeds execution (sometimes dramatically).## Default: off## Example:# debug-mode on
Instance not responding
About Zope debug mode:Errors in product initialization prevent startup
Elements from skin layers (templates, scripts, etc) can be edited while the server is running
Start Zope in debug mode:buildou.cfg
[instance]recipe = plone.recipe.zope2instancedebug-mode = on
Zope Python console
Access database directly:
$ INSTANCE_HOME/bin/zopectl debugStarting debugger (the name "app" is bound to the top-levelZope object)>>> app
>>> app.plone
>>> app.plone.portal_catalog(portal_type='News Item')[]>>>
Zope Python console
Tab completion:
>>> import rlcompleter>>> import readline>>> readline.parse_and_bind("tab: complete")>>> app.plone.portal_catalog.search
Authentication:
>>> from AccessControl.SecurityManagement import newSecurityManager>>> app.acl_users.getUserById('admin').__of__(app.acl_users)>>> newSecurityManager(None, user)
Zope Python console
Synchronization:
>>> app._p_jar.sync()
Transactions:
>>> import transaction
>>> transaction.commit()# Explicit commit
>>> transaction.abort()# Transaction aborted
>>> transaction.savepoint()# Savepoint
>>> app._p_jar.sync()
>>> app._p_jar.sync()
Python debugger
Set a breakpoint:
Post-mortem:
try: return self.getField('photo').tag(self, **kwargs)except: import pdb, sys e, m, tb = sys.exc_info() pdb.post_mortem(tb)
>>> import pdb; pdb.set_trace()
INSTANCE_HOMT/plone/ATContentTypes/content/newsitem.py(133)tag()->None-> import pdb; pdb.set_trace((Pdb) self
(Pdb) self.getField('image')
(Pdb) self.getField('photo')
>>> import pdb; pdb.set_trace()
Server IO errors
No space left on device
Check disc space available for database
Check disc space at /tmp dir
Other errors:No such file or directory
Too many open files
Read-only file system
...
Debugging security issues
Default traceback gives poor information:
... Module Products.CMFPlone.browser.ploneview, line 111, in _initializeData Module plone.memoize.view, line 55, in memogetter Module plone.app.layout.globals.context, line 123, in object_title Module Products.CMFPlone.utils, line 158, in pretty_title_or_id Module Products.CMFPlone.utils, line 463, in base_hasattr Module Products.CMFPlone.utils, line 474, in safe_hasattr Module Shared.DC.Scripts.Bindings, line 184, in __getattr__Unauthorized: You are not allowed to access 'Title' in this context
Debugging security issues
Enable verbose security
INSTANCE_HOME/etc/zope.conf:security-policy-implementation pythonverbose-security on
buildout.cfg:[instance]recipe = plone.recipe.zope2instanceverbose-security = on
Debugging security issues
More informative traceback:
Module plone.app.layout.globals.context, line 123, in object_title Module Products.CMFPlone.utils, line 158, in pretty_title_or_id Module Products.CMFPlone.utils, line 463, in base_hasattr Module Products.CMFPlone.utils, line 474, in safe_hasattr Module Shared.DC.Scripts.Bindings, line 184, in __getattr__ Module AccessControl.ImplPython, line 563, in validate Module AccessControl.ImplPython, line 461, in validate Module AccessControl.ImplPython, line 808, in raiseVerboseUnauthorized: Your user account does not have the required permission. Access to 'Title' of (ATNewsItem at /plone/new-website-soon) denied. Your user account, usertest, exists at /plone/acl_users. Access requires one of the following roles: ['Contributor', 'Editor', 'Manager', 'Owner', 'Reader']. Your roles in this context are ['Authenticated', 'Member'].
Debugging security issues
Reminder about Zope security:Permissions Roles
Roles Principals
Principals (Groups and Users)
Groups Users
Debugging security issues
Use the Python console:
>>> app.plone.restrictedTraverse('/path/to/object')
>>> from AccessControl.SecurityManagement import newSecurityManager>>> app.acl_users.getUserById(USERNAME).__of__(app.acl_users)>>> newSecurityManager(None, user)
Debugging Tools
Gloworm:http://plone.org/products/gloworm
Firebug-like inspector
Provides usefull information about viewlets and viewlet managers
Includes viewlet management operations
Debugging Tools
ZPTDebugger:http://plone.org/products/zptdebugger
Debug Python expressions used in page templates
May record information about all templates called
Profilling information
Debugging Tools
Clouseau:http://plone.org/products/clouseau
A web based (through-the-Plone) Python console
Useful mainly if you don't have access to the filesystem
Nice auto-complete features
Debugging Tools
PDBDebugMode:http://plone.org/products/pdbdebugmode
Launches a pdb post-mortem debugger on exceptions
Works only in debug mode
Respects ignored exceptions in error_log
Additional Resources
Python Debugger:http://plone.org/documentation/how-to/using-pdb
http://docs.python.org/library/pdb.html
Questions?
Ricardo Alves