Gunicorn throws OSError Errno 1 when starting
Asked Answered
C

2

13

I am trying to deploy Django 1.5 using Gunicorn / nginx / supervisor, but at this stage, I'm just trying to get Gunicorn to start properly.

I am trying to start with the command line:

gunicorn project.wsgi:application --workers 3 --user=django --group=django --bind=127.0.0.1:8100

and it fails with

OSError: [Errno 1] Operation not permitted: '/tmp/wgunicorn-c7BU9r'

The traceback:

2013-11-01 20:03:24 [17860] [INFO] Starting gunicorn 18.0
2013-11-01 20:03:24 [17860] [INFO] Listening at: http://127.0.0.1:8000 (17860)
2013-11-01 20:03:24 [17860] [INFO] Using worker: sync
Traceback (most recent call last):
  File "/opt/envs/bedlounge-front/bin/gunicorn", line 9, in <module>
    load_entry_point('gunicorn==18.0', 'console_scripts', 'gunicorn')()
  File "/opt/envs/bedlounge-front/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 71, in run
    WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
  File "/opt/envs/bedlounge-front/lib/python2.7/site-packages/gunicorn/app/base.py", line 143, in run
    Arbiter(self).run()
  File "/opt/envs/bedlounge-front/lib/python2.7/site-packages/gunicorn/arbiter.py", line 175, in run
    self.manage_workers()
  File "/opt/envs/bedlounge-front/lib/python2.7/site-packages/gunicorn/arbiter.py", line 470, in manage_workers
    self.spawn_workers()
  File "/opt/envs/bedlounge-front/lib/python2.7/site-packages/gunicorn/arbiter.py", line 529, in spawn_workers
    self.spawn_worker()
  File "/opt/envs/bedlounge-front/lib/python2.7/site-packages/gunicorn/arbiter.py", line 482, in spawn_worker
    self.cfg, self.log)
  File "/opt/envs/bedlounge-front/lib/python2.7/site-packages/gunicorn/workers/base.py", line 49, in __init__
    self.tmp = WorkerTmp(cfg)
  File "/opt/envs/bedlounge-front/lib/python2.7/site-packages/gunicorn/workers/workertmp.py", line 25, in __init__
    util.chown(name, cfg.uid, cfg.gid)
  File "/opt/envs/bedlounge-front/lib/python2.7/site-packages/gunicorn/util.py", line 157, in chown
    os.chown(path, uid, gid)
OSError: [Errno 1] Operation not permitted: '/tmp/wgunicorn-c7BU9r'

If I start without the user and group arguments (as my regular user), it starts just fine. My understanding is that I would want to start this under another user or group however.

Can anyone help me with what I'm doing wrong? Or any info that would help me solve this?

Thanks!

Cichlid answered 2/11, 2013 at 0:18 Comment(1)
In case someone is looking for an upstart configuration for Django / Gunicorn project ...Nab
A
9

The problem may lie with your userid attempting to start the process as another user. I'm assuming you've created the user and group in the OS. You could try your previous command as root or use sudo.

I use the following Supervisor configuration which specifies the user on both the command line and as an option:

[program:gunicorn]
command=/opt/mysite/virtual_env/bin/python \
    /opt/mysite/virtual_env/bin/gunicorn_django -w 2 --user=appsrun
directory = /opt/mysite/virtual_env/app/
user = appsrun
Areopagite answered 2/11, 2013 at 9:9 Comment(4)
Is there anything that is (or should be) special about the user that you run gunicorn as? Aside from having created it, which I did, is there anything else that it needs?Cichlid
Looks like you were right. Starting the script as root worked fine. Thanks!Cichlid
Running the script as root is a no no no :(Quesenberry
in my case the problem was that I was using USER=$(whoami) GROUP=www-data and even though the user belongs to that group, I had to remove the --group in order to fix this errorQuesenberry
P
1

One workaround for this problem is to change the user and group IDs with which gunicorn is run to match the system (or container) UID and GID:

$ gunicorn --user $(id -u) --group $(id -g) [..] app:app

One scenario when this happens is when you start a python app with gunicorn when --group is set to 0, or any other value different from the one used in the folder where gunicorn was installed (as it seems to attempt to write its temporary files in its current runtime/installation folder, rather than the /tmp it shows in its error message).

Strangely this apparent gunicorn bug persists even today (6 years later, under the latest stable versions of Python (3.11), Ubuntu (22.04 LTS) and gunicorn (20.1.0)). Django is not involved (this issue happens also with Flask).

Pamphylia answered 24/6, 2023 at 15:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.