<commit_before>
#fab prepare_peer -i ~/.ssh/santiago.pem

from fabric.api import *

serverIP = ""

peer1 = ""
peer2 = ""

peers = [
	peer1,
	peer2
]

server = [
	serverIP
]

env.roledefs = {
	'peers': peers,
	'server': server
}

env.user = "ubuntu"


@parallel
def prepare_peer_detailed():
	# kill chrome
	run("pkill chrome")

	# kill ifstat
	sudo("pkill ifstat")

	# launch the app
	run("sh -c 'export DISPLAY=localhost:1.0; nohup google-chrome --load-and-launch-app=/home/ubuntu/collab/ &'"

    NETSTAT_FILE="netstat_192.168.1.10${i}.txt"

    # remove previous netstat files
    sudo("rm /home/ubuntu/netstat*")

    # remove downloaded files
    sudo("rm -f ~/Downloads/*")

    # start ifstat
    sudo("ifstat -i edge0 -ntwb 1 >> /home/ubuntu/"+NETSTAT_FILE+" &")




@parallel
@roles('peers')
def prepare_peer():
    #env.hosts = env.roledefs["peers"]
    prepare_peer_detailed()

@roles('server')
def prepare_server():
    #env.roles = ['server']
	prepare_server()<commit_msg>Finally managed to configure the script to automatically configure the peers and setup all the necessary services. The problem was with the display selected for running the google chrome application and collab.<commit_after># How to run a routine
# fab prepare_peer -i ~/.ssh/santiago.pem

from fabric.api import *
from fabric.contrib.console import confirm

serverIP = ""

peer1 = ""
# peer2 = ""

peers = [
    peer1
]

server = [
    serverIP
]

env.roledefs = {
    'peers': peers,
    'server': server
}

env.user = "ubuntu"


def safeexec(command, execSudo=False, warningOnlyOnFailure=True):
    with settings(warn_only=warningOnlyOnFailure):

        if execSudo == True:
            result = sudo(command)
        else:
            result = run(command)

    if result.failed:
        msg = 'Command [' + command + '] returned non-zero.'
        print(msg)

    return result



@parallel
def prepare_peer_detailed():
    ### kill chrome
    safeexec("pkill chrome")

    ### kill ifstat
    safeexec("pkill ifstat")

    ### update the chrome app code
    safeexec("rm -rf ~/collab && git clone https://github.com/santiagocasti/collab.git")

    ipAddress = safeexec("ifconfig eth0 | awk '/inet addr/ {gsub(\"addr:\", \"\", $2); print $2}'")
    splittedIp = ipAddress.split(".")
    display = "ip-" + splittedIp[0] + "-" + splittedIp[1] + "-" + splittedIp[2] + "-" + splittedIp[3] + ":1"
    print("Display: "+display)

    safeexec("sleep 2")

    ## launch the app
    result = safeexec("export DISPLAY="+display+"; nohup google-chrome --load-and-launch-app=/home/ubuntu/collab/ &")
    print("Result was["+result+"]")

    #
    # create the folder for all the data
    ipAddress = safeexec("ifconfig edge0 | awk '/inet addr/ {gsub(\"addr:\", \"\", $2); print $2}'")
    date = safeexec("date +'%Y-%m-%d_%H-%M-%S'")

    folderName = ipAddress + "_" + date
    folderPath = "/home/ubuntu/" + folderName
    safeexec("mkdir " + folderPath)

    # this file name has to change for every peer
    netstatFileName = "netstat_"+ ipAddress +".txt"
    netstatFilePath = folderPath + "/" + netstatFileName
    safeexec("touch "+netstatFilePath)


    # remove previous netstat files
    safeexec("rm /home/ubuntu/netstat*", True)

    # remove downloaded files
    safeexec("rm -f ~/Downloads/*", True)

    # start ifstat
    safeexec("ifstat -i edge0 -ntwb 1 >> " + netstatFilePath + " &", True)

    print(ipAddress + safeexec("date"))


def prepare_server_detailed():
    # restart memcached
    safeexec("service memcached restart", True)

    # kill node js if running
    safeexec("pkill nodejs", True)

    # start server side main thread
    safeexec("nodejs /home/ubuntu/collab/components/serverSide/main.js &")

    # start experiment
    safeexec("nodejs /home/ubuntu/collab/components/serverSide/triggerTestStart.js")


@parallel
@roles('peers')
def prepare_peer():
    env.always_use_pty = False
    #env.hosts = env.roledefs["peers"]
    prepare_peer_detailed()


@roles('server')
def prepare_server():
#env.roles = ['server']
    prepare_server_detailed()
{'fraction_non_alphanumeric': 0.14799310514651565, 'fraction_numerical': 0.008372322088155627, 'mean_word_length': 3.316684378320935, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '400005', 'n_tokens_mistral': 1429, 'n_tokens_neox': 1336, 'n_words': 332}