Search code examples
pythonubuntuenvironment-variablesdaemon

How to set a python path when using runit


I am am using runit to manage a process on Ubuntu 12.04. I get the below error in the logs when I run:

sv up test/

I assume it is a python path issue.

ImportError: No module named htcommon.ht_redis
Traceback (most recent call last):
  File "/home/ubuntu/workspace/htFrontEnd/htanalytics/ht_rpc_server.py", line 17, in <module>
    from htpData import HTPItemBase, HTPUserBase
  File "/home/ubuntu/workspace/htFrontEnd/htanalytics/htpData.py", line 9, in <module>
    from htcommon.ht_redis import HTRedisConnection
ImportError: No module named htcommon.ht_redis]

I have also set the path in /etc/environment and also set in .bashrc.

Below is my runit script.

#!/bin/sh
exec 2>&1
exec export PYTHONPATH=$PYTHONPATH:/home/ubuntu/workspace/htFrontEnd/heythat
exec export PYTHONPATH=$PYTHONPATH:/home/ubuntu/workspace/htFrontEnd/heythat/htanalytics
exec /usr/bin/python /home/ubuntu/workspace/htFrontEnd/htanalytics/ht_rpc_server.py >> /tmp/ht_rpc_server.log 2>&1
root@aws-rpc-server-east-staging-20130203070552:/etc/sv# 

When I run the process from the command line I get no issues and it works.

/usr/bin/python /home/ubuntu/workspace/htFrontEnd/heythat/htanalytics/ht_rpc_server.py

Why will runit not work? Why can it not find the path?


Solution

  • Look like a few potential problems with this script. I don't think an 'export' can be 'exec'd. At least, it fails in my version of bourne. The exec command replaces the current process (your script) with the called command and doesn't return unless the called command fails. So, it doesn't make sense to 'exec' the exports anyway. Also they can be collapsed into one line. So, you're script should look more like this:

    #!/bin/sh
    export PYTHONPATH=$PYTHONPATH:/home/ubuntu/workspace/htFrontEnd/heythat:/home/ubuntu/workspace/htFrontEnd/heythat/htanalytics
    exec /usr/bin/python /home/ubuntu/workspace/htFrontEnd/htanalytics/ht_rpc_server.py >> /tmp/ht_rpc_server.log 2>&1