Mese Mese - 6 days ago 6
Linux Question

Starting virtualenv script rc local

I'm very newbie in this field and hope someone can help me.

So I have a backend project which I need to launch automatically when the computer switches on (I really don't care how, using systemd or rc.local, my boss told me rc.local, but I guess either will do). I just need to start a docker container, then start my virtualenv and then run the project.

So far I've tried this at


docker start cassandratt #my docker container
sleep 20 #an ugly hack to give time for the container to start
cd /home/backend/
. venv/bin/activate
. /

It doesn't work, but the docker container starts, so I guess the problem is around virtualenv or python, I really don't know as I don't have any experience on this field.

Any idea on how I could accomplish it?

Thanks in advance


Following Samer's guidance I tried creating a folder after activating the virtualenv and it created fine, so I suppore the problem is trying to execute, perhaps loading the virtualenv's python?

docker start cassandratt #my docker container
cd /home/backend/
. venv/bin/activate
mkdir test #folder created fine
. /
mkdir test2 #folder not created


So, partially, the solution seems to set some variables instead of accesing them directly. At least this worked for me. Thanks Samer for giving us a big tip :)

HOME=/home/backend #the project path docker start container . $HOME/venv/bin/activate #activates the virtualenv of the project /usr/bin/env python $HOME/ & #runs the through virtualenv's python #and runs it in the background exit 0