2

In order to run a game server (minecraft) I start it by running this command in CentOS:

java -Xms512M -Xmx1G -jar minecraft_server.jar

But I have no idea how to stop this file from running. I assume it has it's own internal command but considering it might be started in background and running for a very long time, how can I stop this Java command?

Thank you.

2 Answers 2

3

You can use a combination of ps and kill to stop the particular process.

You would first do ps -aux | grep minecraft to get the process number - which is the second field, first number.

Then you can issue kill $PID to send SIGTERM to the process and have it gracefully shutdown.

2
  • deleting mine, yours looks nicer (yes, I know about a non drastic kill, was just being quick).
    – mdpc
    Dec 18, 2012 at 20:41
  • Then check, and if that doesn't stop the process then enter kill -9 $PID.
    – mdpc
    Dec 18, 2012 at 20:42
0

You can use the following 2 files to start/stop service.jar

start.sh

#!/usr/bin/env bash
PID=0
if [ -f './pid' ]; then
    PID=$(cat ./pid)
fi

if ps -p $PID > /dev/null
then
   echo "Service with $PID is already running"
else
    nohup java -jar ./service.jar > service.out 2> errors.txt < /dev/null & PID=$!; echo $PID > ./pid
fi

stop.sh

#!/usr/bin/env bash
if [ -f './pid' ]; then
    PID=$(cat ./pid) && kill -15 $PID
fi

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .