Score:0

systemd start a script that activate virtual env not take effect

cn flag

I was trying to systemd a flask app. I tried to write a script like this:

#!/bin/bash
cd /path/to/app
source venv/bin/activate
python start.py

and just ExecStart this script in the .service file. But this doesn't quite work as starting the service errors with

python: command not found

I actually ran into quite a few issues, but eventually resolved with service file:

[Service]
WorkingDirectory=/path/to/app
ExecStart=/path/to/app/venv/bin/python start.py

Without WorkingDirectory, the file paths do not seem to work as the static file can't even be found.

So my question is actually why doesn't script above in the beginning work? The cd took effect, but the venv activate didn't?

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.