1

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

WorkingDirectory=/home/myproject...
ExecStart==/home/myproject/myprojectenv/bin/gunicorn...

Can any virtual environment start it for all virtuenenv?

CodeMan
  • 111
  • 1
  • 2

1 Answers1

2

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 gunicorn@myprojectenv.service
systemctl start gunicorn@myprojectenv.service

Thus %i will be replaced with myprojectenv. Repeat this for every instance you want to create.

Further reading:

Michael Hampton
  • 244,070
  • 43
  • 506
  • 972