Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. NODE_ENV=myEnvironment pm2 start node/pathToApplication --name myApp
  2.  
  3. echo "Enabling autostartup..."
  4. # Create startup file for pm2
  5. sudo pm2 startup ubuntu -u myUser
  6. # Save startup config
  7. pm2 save
  8. echo "Enabled autostartup"
  9. #
  10.  
  11. pm2 flush
  12.  
  13. function run {
  14. ssh "$address" /bin/bash "$@"
  15. }
  16.  
  17. run << SSHCONNECTION
  18. echo "Killing old running processes"
  19. pm2 stop node/pathToApplication
  20. pm2 kill
  21.  
  22. echo "Starting server..."
  23. NODE_ENV=myEnvironment pm2 start pathToApplication --name appName
  24. echo "Server Started"
  25. # Enable autostartup
  26.  
  27. # systemd is required for the autostartup
  28. sudo dpkg-query -W -f='${Status}' systemd 2>/dev/null | grep -c "ok installed" > /home/$user_q/systemd-check.txt
  29. systemdInstalled=$(cat /home/$user_q/systemd-check.txt)
  30. rm /home/$user_q/systemd-check.txt
  31.  
  32. if [[ $systemdInstalled -eq 0 ]]; then
  33. echo "Systemd is not currently installed. Installing..."
  34.  
  35. # install systemd
  36. sudo apt-get update
  37. sudo apt-get -y install systemd
  38. sudo rm /run/nologin
  39.  
  40. else
  41. echo "systemd is already installed. Skipping this step."
  42. fi
  43.  
  44. # Check of server started successfully, only then save the autostartup profile
  45. if [[ $(pm2 list | awk '{if ($10 == "online") print "OK"}') == "OK" ]]; then
  46. echo "Enabling autostartup..."
  47. # Create startup file for pm2
  48. sudo pm2 startup ubuntu -u myUser
  49. #Save startup config
  50. pm2 save
  51. echo "Enabled autostartup"
  52. #
  53. else
  54. echo "myApp has not started, cannot create autostartup."
  55. fi
  56.  
  57. exit
  58. SSHCONNECTION
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement