Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- NODE_ENV=myEnvironment pm2 start node/pathToApplication --name myApp
- echo "Enabling autostartup..."
- # Create startup file for pm2
- sudo pm2 startup ubuntu -u myUser
- # Save startup config
- pm2 save
- echo "Enabled autostartup"
- #
- pm2 flush
- function run {
- ssh "$address" /bin/bash "$@"
- }
- run << SSHCONNECTION
- echo "Killing old running processes"
- pm2 stop node/pathToApplication
- pm2 kill
- echo "Starting server..."
- NODE_ENV=myEnvironment pm2 start pathToApplication --name appName
- echo "Server Started"
- # Enable autostartup
- # systemd is required for the autostartup
- sudo dpkg-query -W -f='${Status}' systemd 2>/dev/null | grep -c "ok installed" > /home/$user_q/systemd-check.txt
- systemdInstalled=$(cat /home/$user_q/systemd-check.txt)
- rm /home/$user_q/systemd-check.txt
- if [[ $systemdInstalled -eq 0 ]]; then
- echo "Systemd is not currently installed. Installing..."
- # install systemd
- sudo apt-get update
- sudo apt-get -y install systemd
- sudo rm /run/nologin
- else
- echo "systemd is already installed. Skipping this step."
- fi
- # Check of server started successfully, only then save the autostartup profile
- if [[ $(pm2 list | awk '{if ($10 == "online") print "OK"}') == "OK" ]]; then
- echo "Enabling autostartup..."
- # Create startup file for pm2
- sudo pm2 startup ubuntu -u myUser
- #Save startup config
- pm2 save
- echo "Enabled autostartup"
- #
- else
- echo "myApp has not started, cannot create autostartup."
- fi
- exit
- SSHCONNECTION
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement