RhodeCode won't start from start-stop-daemon... again

Issue #282 resolved
Sean Russell created an issue

Upgraded from 1.2.1 to 1.2.2, and RhodeCode won't start again. This time it's because of:

{{{ (rhodecode-venv)root@haselmaus:/var/www/rhodecode# cat rhodecode.log Traceback (most recent call last): File "/var/www/rhodecode-venv/bin/paster", line 8, in <module> load_entry_point('PasteScript==1.7.4.2', 'console_scripts', 'paster')() File "/var/www/rhodecode-venv/lib/python2.6/site-packages/paste/script/command.py", line 104, in run invoke(command, command_name, options, args[1:]) File "/var/www/rhodecode-venv/lib/python2.6/site-packages/paste/script/command.py", line 143, in invoke exit_code = runner.run(args) File "/var/www/rhodecode-venv/lib/python2.6/site-packages/paste/script/command.py", line 238, in run result = self.command() File "/var/www/rhodecode-venv/lib/python2.6/site-packages/paste/script/serve.py", line 279, in command self.logging_file_config(log_fn) File "/var/www/rhodecode-venv/lib/python2.6/site-packages/paste/script/command.py", line 788, in logging_file_config here=os.path.dirname(config_file))) File "/usr/lib/python2.6/logging/config.py", line 76, in fileConfig formatters = _create_formatters(cp) File "/usr/lib/python2.6/logging/config.py", line 133, in _create_formatters c = _resolve(class_name) File "/usr/lib/python2.6/logging/config.py", line 94, in _resolve found = import(used) File "/var/www/rhodecode-venv/lib/python2.6/site-packages/rhodecode/init.py", line 39, in <module> _rev = get_current_revision(quiet=True) File "/var/www/rhodecode-venv/lib/python2.6/site-packages/rhodecode/lib/init.py", line 403, in get_current_revision except (ImportError, RepositoryError, VCSError), err: UnboundLocalError: local variable 'RepositoryError' referenced before assignment }}}

I'm guessing it's another case of RhodeCode expecting there to be initialized environment variables when there aren't any, but I haven't tracked this one down yet (see #267)

Comments (11)

  1. Marcin Kuzminski repo owner

    Just update vcs to 0.2.2 manually, I have no idea why the upgrade didn't do it, (vcs 0.2.2 is in requirements of rhodecode 1.2.2)

  2. Sean Russell reporter

    That's strange; I can start RhodeCode by hand, and it runs fine, which is why I assumed it was an environment issue. I used pip install --upgrade to do the upgrade, if that makes a difference.

  3. Sean Russell reporter

    I upgraded vcs with:

    pip install --upgrade -e hg+https://rhodecode.org/vcs#egg=vcs
    

    It turns out that this isn't correct, because RhodeCode now complains that:

    pkg_resources.VersionConflict: (vcs 0.2.3 (/var/www/rhodecode-venv/src/vcs), Requirement.parse('vcs==0.2.2'))
    

    So I downgraded back to 0.2.2 with:

    pip install --upgrade vcs
    

    which lets me run RC manually again, but gives me the same error in the logs when I try to run it from the init script.

  4. Marcin Kuzminski repo owner

    The error is about failing to Import exception from vcs library... Can you patch the rhodecode/init.py file and move the imports of vcs from outside of try except block? and see what error it throws ?

  5. Sean Russell reporter

    In rhodecode/lib/init.py, there was only one other import from vcs that I could find, and that was in get_changeset_safe(). I moved the try outside of that (so that all vcs imports are in try/except), and I get the same exception in the same place. I didn't see any references to vcs in rhodecode/init.py.

    I don't know Python, but I can't see from the exception that it's failing to import RepositoryError; at least, it's not complaining about being unable to import it; it just can't find it when it tries to use it.

    There are 14 other files that import things from vcs... should I patch all of them?

  6. Marcin Kuzminski repo owner

    Example get_current_revision, this is proposed solution to this problem. SInce this code is really handy only for development

    def get_current_revision(quiet=False):
        """
        Returns tuple of (number, id) from repository containing this package
        or None if repository could not be found.
        
        :param quiet: prints error for fetching revision if True
        """
    
        try:
            from vcs import get_repo
            from vcs.utils.helpers import get_scm
            repopath = os.path.join(os.path.dirname(__file__), '..', '..')
            scm = get_scm(repopath)[0]
            repo = get_repo(path=repopath, alias=scm)
            tip = repo.get_changeset()
            return (tip.revision, tip.short_id)
        except Exception, err:
            if not quiet:
                print ("Cannot retrieve rhodecode's revision. Original error "
                       "was: %s" % err)
            return None
    
  7. Sean Russell reporter

    Applied the change, and now it passes that part. However, the fix for the unset HOME or USERPROFILE env variable is now failing:

    ...
      File "/var/www/rhodecode-venv/lib/python2.6/site-packages/vcs/backends/__init__.py", line 13, in <module>
        from vcs.conf import settings
      File "/var/www/rhodecode-venv/lib/python2.6/site-packages/vcs/conf/settings.py", line 10, in <module>
        raise Exception("You need to set HOME or USERPROFILE env variable")
    Exception: You need to set HOME or USERPROFILE env variable
    Removing PID file /var/www/rhodecode/rhodecode.pid
    

    RhodeCode seemed to work with my trivial change for #267... why is $HOME required? Shouldn't .vcsrc be optional? What is the value in failing if it can't be located?

  8. Sean Russell reporter

    So, if I change settings.py to my little fix, such that:

    if not VCSRC_PATH:
        HOME_ = os.getenv('HOME',os.getenv('USERPROFILE', ''))
    
    VCSRC_PATH = VCSRC_PATH or abspath(HOME_, '.vcsrc')
    

    then RhodeCode starts up from start-stop-daemon and appears to work fine. Is there something that's going to horribly fail at some point if I do this?

  9. Former user Account Deleted

    I had this same issue. Rhodecode worked perfectly with "paster serve" but mod_wsgi gave that crazy UnboundLocalError exception that just didn't seem relevant.

    uname -a is: Linux compname 2.6.32-34-generic #77-Ubuntu SMP Tue Sep 13 19:39:17 UTC 2011 x86_64 GNU/Linux

    Took me a long time to figure this out and fix it. And now I find this thread with all the answers...

  10. William Roush

    Had the same issue, put this in my dispatch.wsgi:

    os.environ['HOME'] = '/opt/rhodecode'

    Totally cheating, not sure if this breaks anything either because I've just started with rhodecode and have no clue why Python needs a HOME environment variable, so use at your own risk.

  11. Log in to comment