-1

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?

ttmtran
  • 3
  • 1
  • 4

2 Answers2

0
  1. hint: it's in The /usr/sbin Directory.

    The /usr/sbin directory contains non-vital system utilities that are used after booting (i.e., starting the system) by the system administrator.

  2. hint: it's a service.

  3. hint: You got Access denied

Hat-trick! We have sudo for these situations.

sudo service gunicorn restart
Esa Jokinen
  • 46,944
  • 3
  • 83
  • 129
  • 1
    Since the jenkins user probably doesn't have permission to sudo, you might need to give it permission to run the service command with it. See, for example: https://unix.stackexchange.com/questions/192706/how-could-we-allow-non-root-users-to-control-a-system-d-service – Matt Jun 11 '17 at 19:58
  • The jenkins user doesn't have permissin to sudo. I'm still trying to make it work, and I'll try your link, Matt. Thanks! – ttmtran Jun 12 '17 at 01:33
0

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.

daks
  • 673
  • 7
  • 25