SHARE
TWEET

Untitled

a guest Feb 16th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. """
  2. It is a good practice to usually run fabric directly from is
  3. directory folder
  4.  
  5. to install:
  6.     pip install fabric3
  7.    
  8. to run (in fabfile current directory):
  9.     fab test
  10.    
  11. @author: Marco Boaretto
  12. """
  13. import time
  14. from fabric.api import env
  15. from fabric.api import puts
  16. from fabric.api import put
  17. from fabric.api import cd
  18. from fabric.api import sudo
  19. from fabric.api import hide
  20. from fabric.api import execute
  21. from fabric.api import task
  22.  
  23. import warnings
  24. warnings.filterwarnings("ignore")
  25.  
  26. env.hosts = ['user@0.0.0.0']
  27. remote_folder = 'remote/foler/path'
  28.      
  29. def push():
  30.     # Push script in remote folder
  31.     put('teste_1.py', remote_folder)
  32.  
  33. def runbg():
  34.     # Run script in background
  35.     with cd(remote_folder):
  36.         command = 'your command here'
  37.         """
  38.         the use of 'nohup' and '&> /dev/null < /dev/null &) && /bin/true'
  39.         allows the script to run in background
  40.         """
  41.         sudo('(nohup %s &> /dev/null < /dev/null &) && /bin/true' % command)
  42.  
  43. def deploy():
  44.     start = time.time()  
  45.    
  46.     #hide all info to run smoothly
  47.     with hide('running', 'stdout', 'stderr'):
  48.         push()
  49.         runbg()      
  50.        
  51.     puts(' ________')
  52.     puts('< execution finished in %.2fs >' % (time.time() - start))
  53.     puts(' ________')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top