Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save pavankjadda/972dcde09463a21d8c4727ab1f6017dd to your computer and use it in GitHub Desktop.
Save pavankjadda/972dcde09463a21d8c4727ab1f6017dd 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
    
@eSargin
Copy link

eSargin commented Nov 23, 2021

thank u master

@youngminz
Copy link

On Ubuntu 20.04, the systemd does not recognize ExitStatus key with error message: Unknown key name 'ExitStatus' in section 'Service', ignoring.. In this case, you might be change ExitStatus to SuccessExitStatus.

- ExitStatus=143
+ SuccessExitStatus=143

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment