我对 shell 脚本非常不擅长。如何编写一个启动
~/start.sh unturnedrp
并确保它正在运行,如果没有,请再次运行。即使它崩溃了西格塞夫。我需要这个的原因是我的游戏服务器需要每隔几个小时关闭一次,有时它会因为物品超载而崩溃。
编辑:这是 start.sh 的代码
#!/bin/bash
# This script starts a Unturned 3 server on Linux machines
# To start servers with this script, place it next to Unturned.exe
# Syntax: start.sh <instance name>
# Author: fr34kyn01535
export MONO_IOMAP=all
#CONFIG
INSTANCE_NAME=$1
STEAMCMD_HOME="$PWD/../steamcmd"
UNTURNED_HOME="$PWD"
#COLORS
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLLOW='\033[0;33m'
NC='\033[0m'
#Steam checks
STEAMCMD_API=$STEAMCMD_HOME/linux32/steamclient.so
UNTURNED_API=$UNTURNED_HOME/Unturned_Data/Plugins/x86/steamclient.so
printf "Steam: "
if [ -f $STEAMCMD_API ]; then
if diff $STEAMCMD_API $UNTURNED_API >/dev/null ; then
printf "${GREEN}UP TO DATE${NC}\n\n"
else
cp $STEAMCMD_API $UNTURNED_API
printf "${YELLLOW}UPDATING${NC}\n\n"
fi
else
printf "${RED}NOT FOUND${NC}\n\n"
fi
cd $UNTURNED_HOME
if [ -f RocketLauncher.exe ]; then
ulimit -n 2048
mono RocketLauncher.exe $INSTANCE_NAME
else
echo "RocketLauncher not found."
fi
编辑:另外最好检查一下 unturned_api 是否大于 steamcmd_api,如果是,则 cp unturned_api,完成后重启服务器