How to restart gunicorn in Jenkins build?

I’m trying to build a Jenkins job that (1) pulls the latest from Git, (2) builds my Django project, and (3) restarts gunicorn and nginx.

However, when I try to restart gunicorn, I get the following error:

jenkins@digitalocean:/$ /usr/sbin/service gunicorn restart 
Failed to restart gunicorn.service: Access denied

I think this is because the user jenkins doesn’t have access to gunicorn.service? What are some strategies I can use to handle this?

Answer

As said previously, your jenkins user simply doesn’t have the permissions to restart the gunicorn process.

You can in fact give it sudo rights, but another solution is to use virtualenv to isolate your Python application environnement. This way the virtualenv can belong to jenkins user, the process too, and he can restart it.

Attribution
Source : Link , Question Author : ttmtran , Answer Author : daks

Leave a Comment