V
V
Vitaly Yakovenko2013-11-19 21:41:30
bash
Vitaly Yakovenko, 2013-11-19 21:41:30

Script-auto-lifter of the fallen server. Bash, screen, and other joys

Situation:
There is a Java server that crashes from time to time (because it sometimes runs out of memory on the VDS), but generally performs its task. There is a script that I'm trying to check if the server is running, and if it doesn't work, run it.

#!/bin/bash
echo "Server auto up script, Ctrl+C to stop keeping server up.";
while true
do
  sleep 3
  ps cax | grep java > /dev/null
  if [ $? = "1" ]
      then 
        echo 'Server restarting right now!'
        screen -dmS Server "java -jar /path/to/server.jar -Xmx512M -Xms64M -server"
  fi
done

I know that it will react in this way to any other java program - can you suggest a better solution here too?
What is screen for? So that you can connect via ssh, run some preventive commands, look at the current statistics. Otherwise it would be easier:
java -jar /path/to/server.jar -Xmx512M -Xms64M -server &

Problem:
screen is not created. A similar command, such as
screen -dmS Server "sleep 30"
screen creates and waits for 30 seconds, as expected. Interestingly, it
screen -dmS Server "sleep 30 && echo CLUSTERFUCK"
no longer works, there is no new session in the list from screen -ls.
In general, help to understand. Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
egor_nullptr, 2013-11-19
@Xazzzi

Try http://supervisord.org

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question