user1919
user1919

Reputation: 3938

How to execute commands as root using fabric

I am trying to use Fabric to execute some basic commands in a remote server. I haven't used Fabric before and I face some difficulties in executing some commands as.

What I need to do is to connect to the remote server, make a file in a specific directory and then restart the uwsgi server.

Although I am able to do the first two tasks, I can not restart the service as I don't ssh to the server as root user.

This is what I do:

def staging():
   env.hosts = ['user@my_host']

def update_app(app_name):
  with cd(git_folder):
    with settings(warn_only=True):
      sudo('mkdir -p /home/new_folder/test')
      #sudo('sudo su -') # also tried this
      sudo('service uwsgi restart')

When I include the sudo su - command, the fab script is never finished. I just get to be logged in as a root (in the terminal).

Upvotes: 0

Views: 505

Answers (1)

9000
9000

Reputation: 40894

Why not just sudo service uwsgi restart? It should work provided that sudo is configured to allow that without prompting for password.

Upvotes: 1

Related Questions