Last active
February 14, 2019 16:07
-
-
Save MBoaretto25/ff23c3b2a2de28b102c427b61fafd5bc to your computer and use it in GitHub Desktop.
fabfile template for pushing local files to a remote folder, and running script in background.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
It is a good practice to usually run fabric directly from is | |
directory folder | |
to install: | |
pip install fabric3 | |
to run (in fabfile current directory): | |
fab test | |
@author: Marco Boaretto | |
""" | |
import time | |
from fabric.api import env | |
from fabric.api import puts | |
from fabric.api import put | |
from fabric.api import cd | |
from fabric.api import sudo | |
from fabric.api import hide | |
from fabric.api import execute | |
from fabric.api import task | |
import warnings | |
warnings.filterwarnings("ignore") | |
env.hosts = ['[email protected]'] | |
remote_folder = 'remote/foler/path' | |
def push(): | |
# Push script in remote folder | |
put('teste_1.py', remote_folder) | |
def runbg(): | |
# Run script in background | |
with cd(remote_folder): | |
command = 'your command here' | |
""" | |
the use of 'nohup' and '&> /dev/null < /dev/null &) && /bin/true' | |
allows the script to run in background | |
""" | |
sudo('(nohup %s &> /dev/null < /dev/null &) && /bin/true' % command) | |
def deploy(): | |
start = time.time() | |
#hide all info to run smoothly | |
with hide('running', 'stdout', 'stderr'): | |
push() | |
runbg() | |
puts(' ________') | |
puts('< execution finished in %.2fs >' % (time.time() - start)) | |
puts(' ________') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment