start a background process with nohup using fabric

Mo J. Mughrabi picture Mo J. Mughrabi · Jan 8, 2012 · Viewed 16.3k times · Source

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 process but not through fabric. Any advise on how i can solve this?

def start_celerycam():
    '''Start celerycam daemon'''
    with cd(env.project_dir):
        virtualenv('nohup bash -c "python manage.py celerycam --logfile=%scelerycam.log --pidfile=%scelerycam.pid &> %scelerycam.nohup &> %scelerycam.err" &' % (env.celery_log_dir,env.celery_log_dir,env.celery_log_dir,env.celery_log_dir))

Answer

danodonovan picture danodonovan · Apr 26, 2012

I'm using Erich Heine's suggestion to use 'dtach' and it's working pretty well for me:

def runbg(cmd, sockname="dtach"):
    return run('dtach -n `mktemp -u /tmp/%s.XXXX` %s' % (sockname, cmd))

This was found here.