23. June 2014

How to debug Gradle script

First of all: do not use daemon mode for debugging.

IntelliJ Idea is automatically spawning daemon when you start any Gradle task. You have to attach to remote process.

I wrote small “How to debug” based on info from forums.gradle.org.

You’ll need to set GRADLE_OPTS environment variable to:

-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005

Here is example in PowerShell:

01-command-line-options

$env:GRADLE_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"

Configure Remote debugging in Idea:

02-configure-remote

You do not need to change anything in default configuration.

Now return to command line with your project and invoke task. Gradle will automatically stop and it waits for debugger.

03-start-process

Attach debugger

04-attach-to-process

Here we go 🙂

05-break-point

There is small limitation. You can stop code execution outside DSL e.g. in class method (line 3). You won’t be able to stop execution in Gradle DSL line 10.

You can download sample build script from Github.

2. June 2013

Configure Nginx with uWSGI to serve Pootle

It’s quite easy to set up Pootle. Just follow the manual – Quickstart.

virtualenv /var/www/pootle/env/
 source /var/www/pootle/env/bin/activate
 (env) $ pip install pootle
 (env) $ pootle init
 (env) $ pootle syncdb --noinput
 (env) $ pootle initdb

You can start Pootle with default CherryPy server. In order to boost performance it is necessary to use more powerfull server.

Let’s take intermediate step and serve Pootle by uWSGI.

First of all you’ll need to create wsgi.py file, because this file is missing in default Pootle installation. File: /var/www/pootle/wsgi.py

import os

# this part is only required when running from checkout instead of an install
try:
    import sys
    ROOT_DIR = os.path.abspath(os.path.dirname(__file__))
    sys.path.insert(0, ROOT_DIR) # Top level directory
    import syspath_override
except ImportError:
    # not running from checkout
    pass

# comment the above lines if running from install

os.environ['DJANGO_SETTINGS_MODULE'] = 'pootle.settings'

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()

You can start uWSGI server by following command:

uwsgi --socket 127.0.0.1:3031 --chdir /var/www/pootle/lib/python2.7/site-packages/pootle --wsgi-file wsgi.py --master --virtualenv /var/www/pootle/ --http ":9090"

This will create uWSGI server and you can test it by connecting to http://localhost:9090

Let’s take further step and configure Nginx to server Pootle. We can modify previous command, because we do not need to server it as http at port 9090:

uwsgi --socket 127.0.0.1:3031 --chdir /var/www/pootle/lib/python2.7/site-packages/pootle --wsgi-file wsgi.py --master --virtualenv /var/www/pootle/

Create webroot directory where you will put static assets, just to avoid information leackage. Store there symlinks to assets and static files.

mkdir /var/www/pootle/webroot
ln -s /var/www/pootle/lib/python2.7/site-packages/pootle/assets /var/www/pootle/webroot/
ln -s /var/www/pootle/lib/python2.7/site-packages/pootle/static /var/www/pootle/webroot/

Store configuration to /etc/nginx/sites-available and create symlink to /etc/nginx/sites-enabled. Configuration of site:

upstream emperor {
  server 127.0.0.1:3031;
}

server {
  listen 80;
  server_name pootle.sinusgear.com;
  root /var/www/pootle/webroot;

  access_log /var/log/nginx/pootle.sinusgear.com_access.log;
  error_log /var/log/nginx/pootle.sinusgear.com_error.log;

  location / {
    location ~* ^.+\.$ {
      root /var/www/pootle/webroot/static/styles;
      expires 30d;
    }
    try_files $uri @django;
  }

  location @django {
    root /var/www/pootle;
    include uwsgi_params;
    uwsgi_param UWSGI_FASTROUTER_KEY $host;
    uwsgi_pass emperor;
  }

  location = /robots.txt {
    root /var/www/pootle/webroot/static/;
    access_log off;
  }

  location ~* ^.+\.py$ {
    return 404;
  }
}

Reload Nginx and Pootle should be much faster 🙂

I recommend book Mastering Nginx. You can learn there much more about Nginx configuration.

17. June 2012

How to solve some problems with Drupal after upgrade to PHP 5.4

I’ve found several interesting issue after upgrading PHP 5.3 to PHP 5.4 on Drupal 6 and Drupal 7 sites.

The first biggest problem was that Drupal was displaying Access denied message on all web pages. It was not possible to login to system. Even http://localhost/?q=admin didn’t work.

I had to create temporary session. It is quite easy when using Drush:

drush user-login

Drush displayed one time session for admin. This solved the problem with admin login.

The other issue was that there was Access denied message on every page. There were also other very useful messages flooding each page:

Notice: Undefined index: access in function _menu_link_translate() …

I spent some time searching for any hint how to resolve this weird behavior. It was necessary to delete all Drupal’s caches.

Configuration -> Development -> Performance -> Delete cache

After this clean up Drupal was working correctly.

Then I checked one older Drupal 6 site and there was nice big red warning:

Warning: strtotime() [function.strtotime]: It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier.

The problem was that there was no default timezone in php.ini. It was sufficient to add timezone to /etc/php5/apache2/php.ini to section

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = "Europe/Prague"

You can find more info about timezones at php.net/date.timezone.

After reloading Apache configuration everything was ok.

2. April 2011

Debugging Flex apps in Firefox 4

When you want to debug Flex app just start debugger in Flash Builder. It will launch browser, e.g. Firefox 4.

The problem is that when you stop at break point for too long, Firefox 4 will terminate Flash plugin. Default limit is 45 seconds.

This is useful behavior for normal web, but it’s not good for debugging.

Solution is quite easy.

Type URL: about:config

Enter filter: dom.ipc.plugins.timeoutSecs

Change value to -1

I found this solution at: support.mozilla.com

Happy debugging. 🙂

  • Quick search

  • Links

  • Twitter

    Follow @jurajmichalek on twitter.

  • Comments

  • Tags

  • Topics