http://docs.fabfile.org/en/1.8/
from fabric.api import *
env.hosts = [ 'ec2-54-194-95-11.eu-west-1.compute.amazonaws.com' ] env.user = 'eric' env.key_filename = '/path/to/key.pem'
# Deploy the project @task def deploy(): for host in env.hosts: local('rsync -vrltD --checksum --chmod=+rwx --delete -e "ssh -i /path/to/key.pem" --exclude ".git" --exclude "logs" /local/path/to/website/. www-data@' + host + ':/remove/path/to/website/.')
# Execute: git pull @task def git_pull(): with cd('/path/to/website'): sudo('git pull')
# Execute: npm install @task def npm_install(): with cd('/path/to/website'): sudo('npm install')
# Execute: npm update @task def npm_update(): with cd('/path/to/website'): sudo('npm update')
# Run the migration @task @runs_once def migration(): with cd('/path/to/website'): sudo('grunt migration')
# Check the node status @task def node_status(): sudo('service mywebsite status')
# Start the node server @task def node_start(): sudo('service mywebsite start')
# Stop the node server @task def node_stop(): sudo('service mywebsite stop')
# Restart the node server @task def node_restart(): sudo('service mywebsite restart')
# Reload nginx @task def nginx_reload(): sudo('service nginx reload')
# Tail the error log @task def tail_error(index): host_list = [env.hosts[int(index)]] execute(tail_error_internal, hosts=host_list)
def tail_error_internal(): run('tail -f /path/to/logs/error.log')