Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
159 views
in Technique[技术] by (71.8m points)

python - How to create a service or shell scripts to run a project within virtualenv?

Here's are the commands i'm using to start my project:

nginx -s stop
workon my_project_env
pkill -f uwsgi -9
uwsgi -x /root/my_project/My_web_api/My_web_api.xml
deactivate
nginx

I want to make sure that this project starts even if the server reboots.

But writing a shell command file as xxx.sh is not going to work,

as shell command won't simply work in virtualenv.

All of the command above will just work in the main terminal,

but some command must work on the virtualenv.

How can i work this out?

question from:https://stackoverflow.com/questions/65948404/how-to-create-a-service-or-shell-scripts-to-run-a-project-within-virtualenv

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You will need to call the uwsgi command using the virtualenv's file for uwsgi. that way you won't need to activate the virtualenv.

Something like below,

/path/to/virtualenvs/project-name/bin/uwsgi -x /root/my_project/My_web_api/My_web_api.xml

All the commands that need to be run using virtualenv should be called this way, so that you won't need to activate the virtualenv.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...