• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[Linux] Auto Start Linux If Server Crash

Fyruz

★★★★★
Joined
Feb 7, 2009
Messages
556
Reaction score
19
Location
127.0.0.1
Hello everyone, I am searching for a script or command on linux that if the server crash, or get down, it will automatically get online.
I want this script because I have a global server save each 24 hrs. and when the server save occurs my server shutdown (because i configure like that) but the server stays closed, thats why I want this script.
thank u
 
I know that this thread has few moths, but it is high on the Google's search list, so I responded, because it can be useful for someone else.
Bash script for Linux to keep server online after shutdown.
Tested under Ubuntu 13.10 with TFS version 1.0.
Code:
#!/bin/bash
############################################################################################
# Copyright (c)©2013 Wojciech Bartłomiej Chojnacki <[email protected]>
############################################################################################
# Author homepage should be available at sekai.eu
############################################################################################
# This script is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
############################################################################################
# This script is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
############################################################################################
# You should have received a copy of the GNU General Public License
# along with this script.  If not, see <http ://www.gnu.org/licenses/>.
############################################################################################

warning='\e[01;31m'
hint='\e[01;32m'
cmd='\e[00;00m'
endTag='\e[0m'

#Make sure that user gave required parameters
if [[ ! -n "$1" ]]; then
   echo -e "${warning}Not all required parameters has been specified.${endTag}"
   echo -e "${hint}The correct syntax:${endTag}"
   echo -e "${cmd}$0 yourExecutableNameInCurrentDirectory${endTag}"
   exit 1
fi

currentDirectory="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
date=`date`
executableFile=$1
while [ true ]; do
   echo -e "[${date}]\t${hint}Server is starting...${endTag}"
   cd ${currentDirectory} && ./${executableFile}
done
echo -e "[${date}]\t${warning}Server won't start. This warning should NOT never appear.${endTag}"
You can download it from assets.sekai.eu .
Move script into directory where you store your server executable. Remember to add executable permission for this file:
Code:
chmod +x keep-server-online.sh
You can run it as follows:
Code:
cd pathToYourOTS
./keep-server-online.sh serverExecutableFilename
For example if you keep your server in /srv/ots directory and your executable filename is tfs:
Code:
cd /srv/ots
./keep-server-online.sh tfs
 
Last edited:
Back
Top