Created
February 23, 2013 04:00
-
-
Save buty4649/5018319 to your computer and use it in GitHub Desktop.
Linux用マイクラサーバ起動スクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# mcstartup.sh - v1.00 | |
# | |
# example directory tree: | |
# ROOT | |
# |-- bin | |
# | `-- mcstartup.sh | |
# |-- etc | |
# | |-- : | |
# | |-- server.log -> /dev/null | |
# | `-- world | |
# | |-- : | |
# |-- jar | |
# | |- 1.4.7 | |
# | | |-- minecraft_server.jar | |
# | | `-- minecraftforge-universal-*.*.*-*.*.*.*.jar | |
# | `-- current.jar -> 1.4.7/minecraftforge-universal-*.*.*-*.*.*.*.jar | |
# `-- log | |
# |-- serverYYYYMMDD.log | |
# |-- : | |
# | |
MC_ROOT=ROOT | |
MC_JAR=${MC_ROOT}/jar/current.jar | |
MC_CONFIG=${MC_ROOT}/etc | |
MC_SERVER_LOG=${MC_CONFIG}/server.log | |
MC_LOCK=${MC_CONFIG}/server.log.lck | |
MC_LOG=${MC_ROOT}/log | |
JAVA=java | |
JAVA_OPTS="-Xmx2048M -Xms2048M" | |
# already running ? | |
if [ -f "${MC_LOCK}" ]; | |
then | |
echo "already running..." | |
exit 1 | |
fi | |
if [ -f "${MC_SERVER_LOG}" ]; | |
then | |
# # server.log rotate | |
# DATE=`tail -1 "${MC_SERVER_LOG}" | awk '{gsub(/-/,"",$1);print $1}'` | |
# | |
# if [ -d "${MC_LOG}" ]; | |
# then | |
# cat "${MC_SERVER_LOG}" >> "${MC_LOG}/server${DATE}.log" | |
# fi | |
# cleanup server.log | |
> ${MC_SERVER_LOG} | |
fi | |
# run minecraft | |
echo -n "minecraft server starting..." | |
cd $MC_CONFIG | |
$JAVA $JAVA_OPTS -jar $MC_JAR 2>&1 | \ | |
while read LINE | |
do | |
DATE=`echo "$LINE" | awk '{gsub(/-/,"",$1);print $1}'` | |
echo "$LINE" >> ${MC_LOG}/server${DATE}.log | |
done & | |
# wait | |
while [ ! -f "${MC_LOCK}" ];do sleep 1; done | |
echo "done." | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment