Reputation: 19817
I have the fabfile as per below. When I manually ssh into the remote server and perform the commands exactly as per the fabfile, it works fine. However, when I run the fabfile, it outputs the same progress as when run manually, reports no errors and exits with "done", but the last line doesn't actually work. Any advice would be great.
After tailing the pserve log and try the fabfile a few more times, randomly it worked once. Nothing had changed and when I ran it subsequently, it didn't work. So I don't know what is going on. Is it a timing thing?
Here is the code:
# kills a running pserve process and restarts it in daemon mode
from fabric.api import *
def deploy():
pid = run("pidof -x pserve") # works
run("sudo kill -15 %s" % pid) # works
with cd('~/Repos/bessie'):
run("sudo pserve development.ini --daemon") # outputs "Entering
# daemon mode" but doesn't
# actually start the process
Output:
[ec2-xxx.ap-southeast-2.compute.amazonaws.com] Executing task 'deploy'
[ec2-xxx.ap-southeast-2.compute.amazonaws.com] run: pidof -x pserve
[ec2-xxx.ap-southeast-2.compute.amazonaws.com] out: 28998
[ec2-xxx.ap-southeast-2.compute.amazonaws.com] out:
[ec2-xxx.ap-southeast-2.compute.amazonaws.com] run: sudo kill -15 28998
[ec2-xxx.ap-southeast-2.compute.amazonaws.com] run: sudo pserve development.ini --daemon
[ec2-xxx.ap-southeast-2.compute.amazonaws.com] out: Entering daemon mode
[ec2-xxx.ap-southeast-2.compute.amazonaws.com] out:
Done.
Upvotes: 2
Views: 432
Reputation: 23331
Basically just sudo('pserve --daemon development.ini', pty=False)
. The pseudo TTY that fabric uses doesn't work very well for detaching processes.
http://docs.fabfile.org/en/1.5/faq.html#init-scripts-don-t-work
Side note, use supervisor, upstart or some other real process manager instead of pserve --daemon
. If your process dies you'll have no real way of knowing using this seutp.
Upvotes: 2
Reputation: 30197
You don't need to:
run("sudo....")
Fabric has a special method for that, sudo()
.
So for one, you can rewrite that line as:
sudo("pserve development.ini --daemon")
Secondly, it looks like it's not fabric then, it's the pserve
itself.
Upvotes: 0