Skip to content

Instantly share code, notes, and snippets.

@ninadpchaudhari
Last active March 20, 2024 06:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save ninadpchaudhari/630dadb3a70f1bdd5fc346e886b534f9 to your computer and use it in GitHub Desktop.
Save ninadpchaudhari/630dadb3a70f1bdd5fc346e886b534f9 to your computer and use it in GitHub Desktop.
Deploying Spring boot apps

Spring Boot app

  1. Create an executable jar
  2. Install Java in your EC2 machine sudo apt install default-jdk
  3. Copy the jar file ( Either use SCP / compile it on EC2)
  4. Open EC2 port 8080
  5. Test using java -jar demoxxxxx.jar
  6. Daemonize the app (Deploy Spring boot app)[https://docs.spring.io/spring-boot/docs/current/reference/html/deployment.html#deployment-systemd-service] File location sudo nano /etc/systemd/system/term.service
Description=term
After=syslog.target

[Service]
User=ubuntu
ExecStart=/usr/bin/java -jar /home/ubuntu/demo-0.0.1-SNAPSHOT.jar
SuccessExitStatus=143

[Install]
WantedBy=multi-user.target

sudo systemctl enable term.service sudo service term start

  1. View Logs journalctl -u term.service

For ExpressJS Apps:

  1. Install Node on your machine sudo apt install npm
  2. Install PM2 sudo npm install -g pm2
  3. Copy your ExpressJS app
  4. Install any depedencies npm install
  5. Run the app in Pm2 sudo pm2 start bin/www
  6. Check the logs! sudo pm2 logs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment