vps ssh whenever i close, after time jar stops running

  1. vps ssh whenever i close, after time jar stops running.

I am new for java, i started jar file on a vps server by the command

$ java -jar MyCode.jar server sample.yml 

and everything works great, but whenever i close ssh, jar file stops. Not right after i stop ssh, i don’t know how long it stays alive, it varies 10min or more, but it definitely closes.

How can i fix it.

  1. And also where i can see all logs. For example after running this command:
    $ java -jar MyCode.jar server sample.yml 

I see logs, but i won’t leave my notebook running forever, where i can view those logs saved somewhere.

  1. And also whenever i open ssh, i firstly have to kill running process and run it again
    $ java -jar MyCode.jar server sample.yml 

To be able to view the logs, and be sure that everything is fine. How can i connect again to the running jar process without restarting?

Download script demo [LINK]
Download script demo [LINK 2]
Download script demo [LINK 2]
Add Comment
2 Answer(s)

Yes, i too faced the issue in my early stage and later searched on web and found the way through SCREEN.

Download demo
Default Answered on April 13, 2021.
Add Comment

When you run a command like this it runs it in the instance of the user being logged in. If you close the shell, it kills the process that is currently running on the user’s account.

There are a couple of ways going around this; I highly recommend using the application screen.

Check to see if the screen is installed on your VPS by running, screen --version. This should output the version that the screen is currently running. If screen is not installed, then it will fail to run. Then you need to install screen using your favorite package manager.

Once you have screen installed, log into your VPS and run the command screen which will open a screen session on your VPS through your user. If you want to name the session that you are starting to run screen -S session_name. You should now be able to run your command without it closing when you exit your VPS.

You can use their keyboard shortcuts to detach from a screen(d), reattach, and list all screens. The prefix for the shortcuts is normally Ctrl+a.

References: https://linuxize.com/post/how-to-use-linux-screen/

Download demo
Professor Answered on June 11, 2020.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.