Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fabric can NOT call the remote script with nohup

In remote server, I have a script test.sh like:

#!/bin/bash
echo "I'm here!"
nohup sleep 100&

From local, I run 'fab runtest' to call the remote test.sh.

def runtest():
    run('xxxx/test.sh')

I can get the output "I'm here!", but I can Not find the sleep process in remote sever. What did I miss?

Thanks!

like image 872
Havy Avatar asked Dec 22 '22 16:12

Havy


2 Answers

It is possible to run the nohup inside the script in remote machine?

I checked the answer here and Fabric FAQ, also get the hints from fabric appears to start apache2 but doesn't and it works for me to combine them together

You can keep your test.sh without changes, and add pty=False with related shell redirection.

from fabric.api import *
def runtest():
    run("nohup /tmp/test.sh >& /dev/null < /dev/null &",pty=False)

At least, it works for me.

like image 130
Larry Cai Avatar answered Jan 07 '23 00:01

Larry Cai


According to the Fabric FAQ you can no longer effectively do this. Instead you should use tmux, screen, dtach or even better use the python daemon package:

import daemon

from spam import do_main_program

with daemon.DaemonContext():
    do_main_program()
like image 20
guidoism Avatar answered Jan 06 '23 23:01

guidoism