diff --git a/ansible/install_setup.yml b/ansible/install_setup.yml index ba46ecfab..71aee0624 100644 --- a/ansible/install_setup.yml +++ b/ansible/install_setup.yml @@ -8,6 +8,7 @@ become: true apt: name: build-essential + update_cache: yes - name: Installation of make become: true diff --git a/ansible/start.sh b/ansible/start.sh index dfee44e55..40177e53a 100644 --- a/ansible/start.sh +++ b/ansible/start.sh @@ -1,5 +1,6 @@ #!/bin/bash - +source ~/.bashrc +~/anaconda3/bin/activate $1 csle stop clustermanager sleep 2 csle start clustermanager diff --git a/ansible/start.yml b/ansible/start.yml index ce839024c..dffc36303 100644 --- a/ansible/start.yml +++ b/ansible/start.yml @@ -4,5 +4,20 @@ tasks: - - name: Start services - script: ./start.sh \ No newline at end of file + - name: Restart postgres + become: true + service: + name: postgresql + state: restarted + + - name: Change permissions on start script + become: true + command: sudo chmod -R u+rwx "/home/{{ user }}/csle/ansible/start.sh" + +- hosts: localhost + connection: local + gather_facts: false + tasks: + - name: Execute script + command: "python /home/{{ user }}/csle/ansible/start_services.py {{ leader_ip }} {{ user }} {{ conda_environment_name }}" + register: script_output \ No newline at end of file diff --git a/ansible/start_services.py b/ansible/start_services.py new file mode 100644 index 000000000..4f1c5104c --- /dev/null +++ b/ansible/start_services.py @@ -0,0 +1,13 @@ +import paramiko +import time +import sys + +if __name__ == '__main__': + ip = sys.argv[1] + user = sys.argv[2] + conda_env = sys.argv[3] + ssh_client = paramiko.SSHClient() + ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) + ssh_client.connect(hostname=ip, port=22, username=user) + stdin, stdout, stderr = ssh_client.exec_command(f"bash -ic 'nohup ~/csle/ansible/start.sh {conda_env} &'", get_pty=True) + time.sleep(120) diff --git a/simulation-system/libs/csle-common/src/csle_common/controllers/traffic_controller.py b/simulation-system/libs/csle-common/src/csle_common/controllers/traffic_controller.py index 169ae18ca..a73dbb316 100644 --- a/simulation-system/libs/csle-common/src/csle_common/controllers/traffic_controller.py +++ b/simulation-system/libs/csle-common/src/csle_common/controllers/traffic_controller.py @@ -168,7 +168,7 @@ def start_client_manager(emulation_env_config: EmulationEnvConfig, logger: loggi ) o, e, _ = EmulationUtil.execute_ssh_cmd(cmd=cmd, conn=emulation_env_config.get_connection( ip=emulation_env_config.traffic_config.client_population_config.docker_gw_bridge_ip)) - time.sleep(2) + time.sleep(5) return True return False