I've been writing a script which installs JSPaint onto 2 ubuntu machines whilst another machine has HAProxy installed onto it to loadbalance the two.
The issue, however, is that jspaint hasnt successfuly installed on the second instance. Here is the code which installs JSPaint:
#installing necessary packages
sudo apt update
#installing git into instance
sudo apt install git -y
#curling code to install nodejs packages
curl -fsSL https://deb.nodesource.com/setup_19.x | sudo -E bash - &&sudo apt-get install -y nodejs
# git cloning jspaint repo
git clone https://github.com/1j01/jspaint.git
cd jspaint
# install node package manager for dependencies
npm i
# executes dev script defined in package
npm run dev
Here is the code for the loadbalancer:
# Installing packages
sudo apt update -y
# Installing haproxy
sudo apt install haproxy -y
# Changing configuration file
sudo sh -c "cat >> /etc/haproxy/haproxy.cfg << _END_
frontend myfrontend
bind 0.0.0.0:1999
default_backend myservers
backend myservers
server server1 $REMOTE_IP1:1999
server server2 $REMOTE_IP2:1999
_END_"
sudo systemctl daemon-reload
# Restart haproxy
sudo systemctl restart haproxy
Both of these scripts are within a directory (which I've called 'files') which is first copied into the instances before being run as per below:
scp -r -o StrictHostKeyChecking=no -i ~/.ssh/$PEM_KEY files ubuntu@REMOTE_IP1:~
scp -r -o StrictHostKeyChecking=no -i ~/.ssh/$PEM_KEY files ubuntu@REMOTE_IP2:~
scp -r -o StrictHostKeyChecking=no -i ~/.ssh/$PEM_KEY files ubuntu@REMOTE_IP_LB:~
ssh -o StrictHostKeyChecking=no -i ~/.ssh/$PEM_KEY ubuntu@$REMOTE_IP1 chmod +x ./files/install.sh
ssh -o StrictHostKeyChecking=no -i ~/.ssh/$PEM_KEY ubuntu@$REMOTE_IP2 chmod +x ./files/install.sh
ssh -o StrictHostKeyChecking=no -i ~/.ssh/$PEM_KEY ubuntu@$REMOTE_IP_LB chmod +x ./files/loadbalancer.sh
ssh -o StrictHostKeyChecking=no -i ~/.ssh/$PEM_KEY ubuntu@$REMOTE_IP1 ./files/install.sh
ssh -o StrictHostKeyChecking=no -i ~/.ssh/$PEM_KEY ubuntu@$REMOTE_IP2 ./files/install.sh
ssh -o StrictHostKeyChecking=no -i ~/.ssh/$PEM_KEY ubuntu@$REMOTE_IP_LB ./files/loadbalancer.sh
I believe the above script appears to do the necessary installation for $REMOTE_IP1 but doesn't seem to run the scripts for either the second IP or the loadbalancer. The only way in which jspaint could be installed was if I manually ssh'd into $REMOTE_IP2 and ran the script to install it. The same logic also follows for the loadbalancing instance.
Is the issue because of the way the scp
and ssh
commands have been written out (i.e. they're only able to configure for the first instance) or is this to do with something else?
Any help would be appreciated.