-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_server.sh
87 lines (74 loc) · 2.01 KB
/
run_server.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
set -euo pipefail
IP="35.178.173.40"
# if [[ $# -eq 0 ]] ; then
# >&2 echo "Usage: ./run_server.sh <IP>"
# >&2 echo "<IP> is the IP of the instance being connected to"
# exit 1
#fi
# Finds ssh key
KEY=$(echo *.pem)
echo "${KEY}"
# Error checking
if [[ -z "${KEY}" ]] ; then
>&2 echo "Error: No ssh permission file could be found in directory"
>&2 echo " Please include the permission file to ssh into the desired instance"
exit 1
fi
WS=" "
if [[ ${KEY} =~ $WS ]]; then
>&2 echo "Error: Multiple ssh permission files found in directory"
>&2 echo " Please have only 1 permission file for the desired instance"
exit 1
fi
# Formatting
TERMINAL_WIDTH=$(tput cols)
SEP=$(echo $(printf '=%.0s' $(eval "echo {1.."$(($TERMINAL_WIDTH))"}")))
echo "$SEP"
echo "Connecting to server instance"
ssh -A -i ${KEY} ubuntu@${IP} << EOF
#!/bin/bash
set -euo pipefail
echo "Connection successful"
echo "$SEP"
#echo "Installing packages"
#sudo apt update
#sudo apt -y install nodejs
#echo "Packages installed successfully"
#echo "$SEP"
echo "Building project"
if [[ -d "Y2_Project" ]]; then
cd Y2_Project
git pull origin master
cd
else
git clone [email protected]:sts219/Y2_Project.git
fi
echo "Most recent version obtained"
echo "$SEP"
if sudo lsof -i -P -n | grep -q mosquitto
then
echo "mosquitto MQTT broker running";
else
echo "Launching mosquitto MQTT broker"
screen -d -m -S mqtt bash -c 'sudo mosquitto -c /etc/mosquitto/mosquitto.conf'
fi
echo "$SEP"
echo "$SEP"
if sudo lsof -i -P -n | grep -q nginx
then
echo "nginx web server running"
else
echo "Launching nginx web server"
sudo systemctl start nginx
fi
echo "$SEP"
echo "$SEP"
echo "Launching REST web service"
screen -d -m -S rest bash -c 'cd ~/Y2_Project/Server && npm start'
echo "$SEP"
echo "Launching REACT web app"
screen -d -m -S react bash -c 'cd ~/Y2_Project/Front_End/React/web-app && npm start'
echo "$SEP"
echo "Server running, Done"
EOF