Reputation: 6693
I have recently set up my game server on a linux OS and am using SSH to run the java file which runs the game server. In order for me to be able to exit the SSH session but keep the server running, I am using nohup and creating a script which does this for me:
#!/bin/bash
cd "RSPS"
echo "Booting the RSPS..."
nohup java -Xmx220m -cp bin:lib/* com.ruseps.GameServer &
I can see the status of my server then at any time by using the tail
command like so:
#!/bin/bash
cd "RSPS"
tail -f nohup.out
However, my server has shutdown hooks which expects the java file to be exited therefor running top
and then kill
ing the PID of the service ignored the shutdown hook thus breaking the 'save' state and making my server unbootable.
Is there a way I can reopen the process and softly kill the service, ie like exiting it so the file can run the shutdown hook?
What I am currently doing, which is not running the shutdown hook is using this via command line:
top
kill PID_HERE
Upvotes: 0
Views: 388
Reputation: 162367
In order for me to be able to exit the SSH session but keep the server running, I am using nohup and creating a script which does this for me:
First of all: Don't do that!
Implement a proper service. If the machine this is running on uses systemd all you have to do is writing a unit file https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/sect-managing_services_with_systemd-unit_files
If your machine uses an init
-script style init system, copy the init script of some similar network service, like a webserver and modify it for your needs.
Keep in mind that you should create a new user/groups for your server to run as and on startup have it check that it's not running as root (because that's always a bad idea).
However, my server has shutdown hooks
How are these hooks implemented? How does your server is notified to shut down? The SIGTERM
signal (which is the default signal sent by kill
, despite its name) is the standard way of informing processes, that they shall terminate gracefully. See the official Java documentation for details: https://docs.oracle.com/javase/7/docs/webnotes/tsg/TSG-VM/html/signals.html
Upvotes: 3