I'm writing startup script for instance template to use in a instance group. All instances of this group are going to use this startup script to run node.js server that is in the GitHub repo that i clone to all instances.
#!/bin/bash
sudo apt-get update
sudo apt-get install -y git
sudo git config --global user.email "[email protected]"
sudo git config --global user.name "UserName"
GITHUB_TOKEN=$(gcloud secrets versions access latest --secret="token")
cd /home/user
sudo -u user git clone https://UserName:${GITHUB_TOKEN}@github.com/UserName/repo.git
cd /home/user/repo
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo gpg --dearmor -o /usr/share/keyrings/nodesource-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/nodesource-archive-keyring.gpg] https://deb.nodesource.com/node_14.x $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/nodesource.list
echo "deb-src [signed-by=/usr/share/keyrings/nodesource-archive-keyring.gpg] https://deb.nodesource.com/node_14.x $(lsb_release -cs) main" | sudo tee -a /etc/apt/sources.list.d/nodesource.list
sudo apt-get install -y nodejs
sleep 10
node -v
sudo apt-get install -y npm
npm -v
sleep 10
sudo node index.js
The startup script is working but except last command, i need to SSH to my VM to run last command to run the server but I don't want to SSH my VM anytime. I want to startup script does all the job and without SSH to my vm, http://localhost:80/ should run server. How can i do this?