Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

On Debian, I have written a simple init script for a Pyramid application using pserve. I am not 100% sure that it is complete/correct, but it works for now:

DAEMON="/home/project/.virtualenvs/project/bin/pserve /home/project/production.ini"
PIDFILE=/home/project/project.pid
USER=project
GROUP=project
CWD=/home/project
LOGFILE=/home/project/project.appserver.log

case "$1" in
  start|stop|restart|status)
    echo "$1 project app server: "
    cd $CWD
    $DAEMON $1 --pid-file=$PIDFILE --user=$USER --group=$GROUP --log-file=$LOGFILE
    RETVAL=$?
    if [ "$RETVAL" -eq "0" ]; then
        echo "Success"
    fi
    ;;
  *)
    echo "Usage: /etc/init.d/project {start|stop|restart|status}"
    exit 1
    ;;
esac

exit 0

When I log in as root, I can run the following without issue:

~# service project start
start project app server: 
Changing user to project:project (200:1001)
Entering daemon mode
Success

I put the following into my Puppet configuration for the machine:

  file { '/etc/init.d/project':
    ensure => present,
    group => 'root',
    mode => 'a=rx,u+w',
    owner => 'root',
    source => 'puppet:///modules/project/project.init',
  }

  service { 'project':
    enable => true,
    ensure => running,
    require => File['/etc/init.d/project'],
  }

However, when I run puppet agent --test, the service is not left in a running state. When I look in the project's log file, I see the following:

...
  File "/home/project/.virtualenvs/project/lib/python2.7/site-packages/project-0.0-py2.7.egg/project/model/__init__.py", line 1, in <module>
    from base import Base, DBSession, initialize_sql
  File "/home/project/.virtualenvs/project/lib/python2.7/site-packages/project-0.0-py2.7.egg/project/model/base.py", line 1, in <module>
    from sqlalchemy import Column, engine_from_config
  File "build/bdist.linux-x86_64/egg/sqlalchemy/__init__.py", line 52, in <module>

  File "build/bdist.linux-x86_64/egg/sqlalchemy/types.py", line 33, in <module>
    except NameError:
  File "build/bdist.linux-x86_64/egg/sqlalchemy/processors.py", line 98, in <module>
  File "build/bdist.linux-x86_64/egg/sqlalchemy/cprocessors.py", line 7, in <module>
  File "build/bdist.linux-x86_64/egg/sqlalchemy/cprocessors.py", line 4, in __bootstrap__
  File "build/bdist.linux-i686/egg/pkg_resources.py", line 882, in resource_filename
  File "build/bdist.linux-i686/egg/pkg_resources.py", line 1351, in get_resource_filename
  File "build/bdist.linux-i686/egg/pkg_resources.py", line 1373, in _extract_resource
  File "build/bdist.linux-i686/egg/pkg_resources.py", line 962, in get_cache_path
  File "build/bdist.linux-i686/egg/pkg_resources.py", line 928, in extraction_error
pkg_resources.ExtractionError: Can't extract file(s) to egg cache

The following error occurred while trying to extract file(s) to the Python egg
cache:

  [Errno 13] Permission denied: '/root/.python-eggs'

The Python egg cache directory is currently set to:

  /root/.python-eggs

As I noted, logging in as root and starting it seems to work fine. I would imagine that Puppet does something similar. What's the missing piece?

share|improve this question

1 Answer 1

The problem is your python egg cache, its trying to write to the root directory. Add the following to your script.

export PYTHON_EGG_CACHE=/var/tmp
share|improve this answer
    
Thanks, that seems to fix it, I guess. Any idea on why it's broken in the first place though? It seems strange that I can run it by hand but not through puppet. –  dave mankoff Oct 31 '12 at 13:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.