Question

I'm using fabric to connect to a remote host. In which I called supervisor to see the status. But I don't know how to use fabric file to exit the supervisor interface. How to do it?

My fabfile is like this:

from fabric.api import run
from fabric.api import env

env.hosts = [
    'my_host'
    ]

def my_fab():
    run("supervisorctl -u 'me' -p 'aaa'")

>>> fab my_fab
>>> # plenty of stdout 
>>> supervisor>                             # I'm stuckled here
Was it helpful?

Solution

This is rather about using supervisorctl than using fabric

Avoid fab calls to commands, requiring user interaction

Fabric does one-shot calls to commands and then returns. Shall be no long term activity on console. The solution for your problem is not to enter interactive mode (which awaits some further input), but call supervisor only in non-interactive mode.

Calling supervisorctl in non-interactive mode

Supervisor control command provides interactive and non-interactive mode.

You non-interacive mode.

E.g. in my installation, I have a service called logproxy

Calling supervisorctl in this way:

$ supervisorctl status logproxy
logproxy                         STOPPED    Not started

Applying this to your fab task shall make it working.

Following the sample code from "Welcome to Fabric!" it would look like:

from fabric.api import run

def super_status():
    uname = "zen"
    pswd = "then"
    cmd = "supervisorctl -u {uname} -p {pswd} status logproxy".format(uname=uname, pswd=pswd)
    # to see the command you are going to call, just for show
    print cmd
    # and run it
    run(cmd)

And would be used.

$ fab -l

to list it.

and calling the task super_status:

$ fab super_status -H localhost
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top