Решено Не могу запустить сервера через CRON

Статус
Закрыто для дальнейших ответов.

SenKou

Активный участник
Баллы
61
Имя в Minecraft
SenKou
Для всех серверов схожие скрипты, лишь изменены пути к файлам и "screen"

Первый скрипт MCServerResetCheck.sh

if ! screen -list | grep -q bunge; then
echo "$(date) $(ls -1 | wc -l):" >> /root/moth/bunge/MCServerRestartLog.txt 2>&1
cd /root/moth/bunge
"/root/moth/bunge/start.sh" | sed 's/^/ /' >> /root/moth/bunge/MCServerRestartLog.txt 2>&1
fi

Второй скрипт start.sh

for session in $(screen -ls | grep -o '[0-9]\{3,\}\.\S*')
do
screen -r bunge -p0 -X stuff "&9Server is restarting.\015"
screen -r bunge -p0 -X stuff "stop\015" # Send "stop\r" to the minecraftServer server.
done

counter=0
while [ $(screen -ls | grep -c 'No Sockets found in') -lt 1 ]; do
if [ $(( $counter % 10 )) -eq 0 ]; then
echo 'A previous server is in use. Waiting for 10 seconds before starting server...'
fi

sleep 1
counter=$((counter+1))
done

echo 'Starting server...'

screen -dmS "bunge" java -Xmx5g -Xms1g -jar moth.jar
sleep 1
while [ $(screen -ls | grep -c 'No Sockets found in') -ge 1 ]; do
echo 'Waiting for 5 seconds to start server...'
sleep 5
screen -dmS "bunge" java -Xmx5g -Xms1g -jar moth.jar
done

echo 'Server started.'


Так выглядит crontab. Запускается только один сервер. Для всех стоит разрешение на запуск. При отключение одного сервера, запускается другой. Но вместе не работаю. Пожалуйста, подскажи, в чём причина?

Файл crontab

* * * * * /root/moth/server/MCServerResetCheck.sh
* * * * * ( sleep 30 ; /root/moth/server/MCServerResetCheck.sh)
* * * * * ( sleep 60 ; /root/moth/sky/MCServerResetCheck.sh)
* * * * * ( sleep 90 ; /root/moth/sky/MCServerResetCheck.sh)
* * * * * ( sleep 120; /root/moth/lobby/MCServerResetCheck.sh)
* * * * * ( sleep 150 ; /root/moth/lobby/MCServerResetCheck.sh)
* * * * * ( sleep 180 ; /root/moth/bunge/MCServerResetCheck.sh)
* * * * * ( sleep 210 ; /root/moth/bunge/MCServerResetCheck.sh)
 
Файл crontab остался прежним

* * * * * /root/moth/server/MCServerResetCheck.sh
* * * * * ( sleep 30 ; /root/moth/server/MCServerResetCheck.sh)
* * * * * ( sleep 60 ; /root/moth/sky/MCServerResetCheck.sh)
* * * * * ( sleep 90 ; /root/moth/sky/MCServerResetCheck.sh)
* * * * * ( sleep 120; /root/moth/lobby/MCServerResetCheck.sh)
* * * * * ( sleep 150 ; /root/moth/lobby/MCServerResetCheck.sh)
* * * * * ( sleep 180 ; /root/moth/bunge/MCServerResetCheck.sh)
* * * * * ( sleep 210 ; /root/moth/bunge/MCServerResetCheck.sh)

Первый скрипт MCServerResetCheck.sh

#!/bin/bash
port_server="25537" #игровой порт сервера
path_server="/root/moth/sky/" #путь к папке с сервером
count=4
while [ $count -gt 0 ]
do
status=$(lsof -i :$port_server | grep -v 'grep' | head -n 1 | awk '{print $2}')
if [ "$status" = "" ];
then
if [ "$count" = "1" ];
then
date=$(date +%Y_%m_%d_%H_%M)
echo "$date: Процесс c портом $port_server не найден. Запуск..." >> /home/scriptlogall.txt
cd $path_server
sh start.sh
fi
count=$[ $count - 1 ]
sleep 5
else
break
fi
done

Второй скрипт start.sh

#!/bin/bash
screen -dmS "sky" java -Xmx5g -Xms1g -jar moth.jar
 
Статус
Закрыто для дальнейших ответов.
Назад
Верх Низ