If you are not working inside an environment, Gunicorn will be installed globally (i.e. available systemwide). This is not recommended. Always opt for using virtualenv. But if you have multiple virtualenvs how many gunicorn.service files should you have to start gunicorn on system startup? For example below
Can any virtual environment start it for all virtuenenv?
You can use systemd instances for this.
For instance, let’s say you create all your virtualenvs in the same directory (this will make it easier anyway).
Then you can write a unit file like this:
WorkingDirectory=/home/myproject/%i ExecStart=/home/myproject/%i/bin/gunicorn ...
The %i represents a particular instance of the unit, of which there can be no limit. You refer to an instance by using an
@ sign followed by the instance name, such as:
systemctl enable [email protected] systemctl start [email protected]
%i will be replaced with
myprojectenv. Repeat this for every instance you want to create.
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.