Sample Header Ad - 728x90

How to run a command inside a virtualenv using systemd

37 votes
2 answers
49876 views
I believe this should be simple but I can't get it to work properly. These are the commands I can run on command line: cd /home/debian/ap # Start a virtualenv source venv-ap/bin/activate # This needs to happen inside the virtualenv and takes ~20 seconds crossbar start # Outside the virtualenv, perhaps in a different command line window python3 /home/debian/myscript.py These commands have to be done in this order. Due to the virtualenv, the non-executable for crossbar, and the separate python script afterwards, I haven't been able to figure out the best way to get this to work. My current work-in-progress: [Unit] Description=Start CB After=network.target [Service] Type=simple User=debian ExecStartPre=source /home/debian/ap/venv-ap/bin/activate ExecStart=cd /home/debian/ap/ && crossbar start Restart=always [Install] WantedBy=multi-user.target
Asked by sscirrus (525 rep)
Dec 7, 2017, 11:38 PM
Last activity: Mar 25, 2022, 08:33 AM