Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jmy2022/5ecd3f1dbf3cedee115b1c816dcd0383 to your computer and use it in GitHub Desktop.
Save jmy2022/5ecd3f1dbf3cedee115b1c816dcd0383 to your computer and use it in GitHub Desktop.
How to create Spring Boot app as Ubuntu service?

How to create Spring Boot app as Ubuntu service?

  1. Create service named employee using vi command
    sudo vim /etc/systemd/system/employee.service
    
  2. Copy paste the following content into the file and make sure to change the ExecStart command arguments
    [Unit]
    Description=Employee Spring Boot application service
    
    [Service]
    User=ubuntu
    ExecStart=/usr/bin/java -Dspring.profiles.active=prod -Dusername="admin" -Dpassword="Password129388" -jar /home/ubuntu/Employee/target/employee-0.0.1-SNAPSHOT.jar 
    ExitStatus=143
    
    TimeoutStopSec=10
    Restart=on-failure
    RestartSec=5
    
    [Install]
    WantedBy=multi-user.target
    
  3. Enable the service
    sudo systemctl enable employee
    
  4. Start the service
    sudo systemctl start employee
    
  5. Reload system daemon
    sudo systemctl daemon-reload
    
  6. Check the service status
    sudo systemctl status employee 
    
  7. Check service logs using the following command
    sudo journalctl -u employee.service --no-pager
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment