In [1]:
from fabric.api import *

env.host_string="ec2-54-201-254-197.us-west-2.compute.amazonaws.com"
env.user = "ubuntu"
env.key_filename = ['/home/zzz/Downloads/Stevens-rzeng3.pem']

In [2]:
# run a command on the server to make sure you're connected
run('uname -a')


[ec2-54-201-254-197.us-west-2.compute.amazonaws.com] run: uname -a
[ec2-54-201-254-197.us-west-2.compute.amazonaws.com] out: Linux ip-172-31-18-1 4.4.0-59-generic #80-Ubuntu SMP Fri Jan 6 17:47:47 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
[ec2-54-201-254-197.us-west-2.compute.amazonaws.com] out: 

Out[2]:
'Linux ip-172-31-18-1 4.4.0-59-generic #80-Ubuntu SMP Fri Jan 6 17:47:47 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux'

In [3]:
# stop the service for your project so you can edit the code
sudo('service myproject stop')


[ec2-54-201-254-197.us-west-2.compute.amazonaws.com] sudo: service myproject stop
Out[3]:
''

In [4]:
# stop nginx so you can use port 41593 for testing
sudo('service nginx stop')


[ec2-54-201-254-197.us-west-2.compute.amazonaws.com] sudo: service nginx stop
Out[4]:
''

In [34]:
# download the current code for your project
get('myproject.py')


[ec2-54-201-254-197.us-west-2.compute.amazonaws.com] download: /home/zzz/Documents/bia660/RongZeng/Assignment4/ec2-54-201-254-197.us-west-2.compute.amazonaws.com/ec2-54-201-254-197.us-west-2.compute.amazonaws.com/ec2-54-201-254-197.us-west-2.compute.amazonaws.com/myproject.py <- /home/ubuntu/myproject.py
Out[34]:
[u'/home/zzz/Documents/bia660/RongZeng/Assignment4/ec2-54-201-254-197.us-west-2.compute.amazonaws.com/ec2-54-201-254-197.us-west-2.compute.amazonaws.com/ec2-54-201-254-197.us-west-2.compute.amazonaws.com/myproject.py']

In [35]:
# see what directory your currently in on the local machine
!pwd


/home/zzz/Documents/bia660/RongZeng/Assignment4/ec2-54-201-254-197.us-west-2.compute.amazonaws.com

In [5]:
import os
os.chdir('ec2-54-201-254-197.us-west-2.compute.amazonaws.com')

In [37]:
# checking to make sure we're in the right working directory
!pwd


sh: 0: getcwd() failed: No such file or directory


In [7]:
ls


myproject.py

In [9]:
# edit the code in a separate window, feel free to use my code
put('myproject.py')


[ec2-54-201-254-197.us-west-2.compute.amazonaws.com] put: myproject.py -> /home/ubuntu/myproject.py
Out[9]:
[u'/home/ubuntu/myproject.py']

In [56]:
# if you are using my code with TextBlob make sure to install TextBlob to the chatbot env
with prefix('source activate chatbot'):
    run('pip install textblob')


[ec2-54-201-254-197.us-west-2.compute.amazonaws.com] run: pip install textblob
[ec2-54-201-254-197.us-west-2.compute.amazonaws.com] out: Requirement already satisfied: textblob in ./anaconda2/envs/chatbot/lib/python2.7/site-packages
[ec2-54-201-254-197.us-west-2.compute.amazonaws.com] out: Requirement already satisfied: nltk>=3.1 in ./anaconda2/envs/chatbot/lib/python2.7/site-packages (from textblob)
[ec2-54-201-254-197.us-west-2.compute.amazonaws.com] out: Requirement already satisfied: six in ./anaconda2/envs/chatbot/lib/python2.7/site-packages (from nltk>=3.1->textblob)
[ec2-54-201-254-197.us-west-2.compute.amazonaws.com] out: 


In [ ]:
# we need to use our chatbot virtual environment to run the server code
with prefix('source activate chatbot'):
    run('python myproject.py')
    
#if you need to stop the server script, just select this cell and click the stop button at the top


[ec2-54-201-254-197.us-west-2.compute.amazonaws.com] run: python myproject.py
[ec2-54-201-254-197.us-west-2.compute.amazonaws.com] out:  * Running on http://0.0.0.0:41953/ (Press CTRL+C to quit)
[ec2-54-201-254-197.us-west-2.compute.amazonaws.com] out: 

In [8]:
# after you've stopped the server, make sure it's not still running remotely
sudo('killall python')


[ec2-54-201-254-197.us-west-2.compute.amazonaws.com] sudo: killall python
/bin/bash: line 1: 21354 Terminated              python myproject.py
[ec2-54-201-254-197.us-west-2.compute.amazonaws.com] out: 
Out[8]:
''

In [11]:
sudo('service myproject start')
sudo('service nginx start')


[ec2-54-201-254-197.us-west-2.compute.amazonaws.com] sudo: service myproject start
[ec2-54-201-254-197.us-west-2.compute.amazonaws.com] sudo: service nginx start
Out[11]:
''

In [ ]: