0

How do I make a script that restarts a java program every X minutes in Linux?

I will be using:

  • PHP
  • A linux godaddy hosting account (classic, and I don't know what OS)
  • a .sh script
  • FTP (to access files)

I am hoping to start a server for minecraft and this is an idea that sounds really cool.

I also need it to be that if I change the script, it restarts and runs the new script instead of the old one. I am hoping to have a php document open the whole time the server is on (If the php document is closed, the server is closed). This should be all in one script/PHP webpage.

Finally, it has to work the first time or I won't be able to stop the program.

I have included a .sh script of what I have so far:

#!/bin/sh
pkill java
screen java -Xmx1024M -jar craftbukkit.jar -o true

Does it work? I need a PHP code to start it up and keep it running while the webpage is loaded.

3
  • What have you tried so far? Where are you stuck in your research? We aren't a script writing service and expect that you have done some footwork up front and letting us know where you are stuck. -1 until you have done some work on your own.
    – nerdwaller
    Jan 7, 2014 at 19:21
  • stackoverflow.com/questions/5882650/… I thought that a combination of this and something like crontab for php would work, but I don't know of anything that could do such a thing. Maybe I could use a delayed stop... Jan 7, 2014 at 20:02
  • if the server is closed, the PHP page is "closed". It's the web service that delivers the HTML content.
    – suspectus
    Jan 7, 2014 at 21:37

1 Answer 1

1

You will kill all java processes, but as I properly understood you want to kill only one. I'd do it like this:

kill $(ps aux | grep '<name of your process>' | grep -v grep | awk '{print $2}')

in .sh file

1
  • you can use pgrep instead of ps .. | grep | grep -v | awk, it will return you the pid of the process :) Oct 29, 2015 at 14:42

You must log in to answer this question.

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