start a background process with nohup using fabric

后端 未结 10 2080
广开言路
广开言路 2020-12-04 22:31

am trying to start a celerycam process using fabric using the below nohup command. Unfortunately, nothing is happening, manually using the same command i could start the pro

10条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-04 22:47

    I was able to circumvent this issue by running nohup ... & over ssh in a separate local shell script. In fabfile.py:

    @task
    def startup():
        local('./do-stuff-in-background.sh {0}'.format(env.host))
    

    and in do-stuff-in-background.sh:

    #!/bin/sh
    
    set -e
    set -o nounset
    
    HOST=$1
    
    ssh $HOST -T << HERE
       nohup df -h 1>>~/df.log 2>>~/df.err &
    HERE
    

    Of course, you could also pass in the command and standard output / error log files as arguments to make this script more generally useful.

    (In my case, I didn't have admin rights to install dtach, and neither screen -d -m nor pty=False / sleep 1 worked properly for me. YMMV, especially as I have no idea why this works...)

提交回复
热议问题