0

I developed a Java server (using Spring) and uploaded the final executable JAR to an EC2 instance using FileZilla. Now I want it to run.

I've connected via SSH and used java -jar server.jar to run my server, and it worked (I've tried accessing it). However once the SSH connection is closed the server obviously stops running as well.

How can I start my application in such a way so it keeps running?

Edit: Using the command screen explained here I was able to run it in background and so it keeps running.

Neo
  • 3,164
  • 2
  • 17
  • 32
  • This might help: https://stackoverflow.com/questions/29843130/how-to-deploy-created-jar-file-in-apache-tomcat-server-in-eclipse-ide – Dusan Bajic Jul 15 '18 at 16:52

2 Answers2

1

The issue is not cloud dependent its the configuration you have to do to run your jar as a service in your system. If you are using Elastic Bean Stalk change systemctl to initctl in below example.

  1. Put the script commands you wish to run in /usr/bin/demoscript.sh
  2. Remember to make the script executable with chmod +x.
  3. Create the following file:

/usr/lib/systemd/system/demo.service

[Unit]
Description=Demo Script

[Service]
Type=forking
ExecStart=/usr/bin/demoscript.sh
  1. Reload the systemd service files: systemctl daemon-reload
  2. Check that it is working with systemctl start demo
Kushagra Misra
  • 431
  • 1
  • 7
  • 15
0

You need to make it run as daemon process in linux.

There are many tutorial / templates available to create a daemon shell script. Quick google search shows github has many templates, so check them out.

Amit
  • 51
  • 3