I'm using python fabric to deploy binaries to an ec2 server and am attempting to run them in background (a subshell).

All the fabric commands for performing local actions, putting files, and executing remote commands w/o elevated privileges work fine. The issue I run into is when I attempt to run the binary.

with cd("deploy"):
        run('mkdir log')
        sudo('iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080', user="root")
        result = sudo('./dbserver &', user="root") # <---- This line
        print result
        if result.failed:
            print "Running dbserver failed"
        else:
            print "DBServer now running server" # this gets printed despite the binary not running

After I login to the server and ps aux | grep dbserver nothing shows up. How can I get fabric to execute the binary? The same command ./dbserver & executed from the shell does exactly what I want it to. Thanks.

有帮助吗?

解决方案

This is likey reated to TTY issues, and/or that you're attempting to background a process.

Both of these are discussed in the FAQ under these two headings:

http://www.fabfile.org/faq.html#init-scripts-don-t-work

http://www.fabfile.org/faq.html#why-can-t-i-run-programs-in-the-background-with-it-makes-fabric-hang

Try making the sudo like this:

sudo('nohup ./dbserver &', user=root, pty=False)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top