Startscript für OpenSim etc - Bogus Curry - 02.07.2014
Hallo zusammen ;D
Ich hab ein schönes Startscript gefunden das eigentlich für einen Minecraft Server gedacht war. Das ganze wurde dann von einen lieben User umgeschrieben, so das dieses auch für OpenSim/Arriba oder halt WhiteCore Sim brauchbar ist.
Hier der Code
Code: #!/bin/bash
##########################################################################
################################ ABOUT ###################################
##########################################################################
# #
# Author: Enrico Ludwig (Morph) #
# Version: 1.0.0.0 (14. May 2014) #
# License: GNU GPL v2 (See: http://www.gnu.org/licenses/gpl-2.0.txt) #
# Created: 14. May 2014 #
# Description: Control your Arriba - Sim #
# #
##########################################################################
########################
### GENERAL SETTINGS ###
########################
SERVER_EXE="OpenSim.exe"
SCREEN_NAME="AS-Chaoslands"
###################
### APPLICATION ###
###################
VERSION="1.0.0.0"
###################
### COLOR CODES ###
###################
COLOR_DEFAULT="\e[39m"
COLOR_LGRAY="\e[37m"
COLOR_RED="\e[31m"
COLOR_YELLOW="\e[33m"
COLOR_GREEN="\e[32m"
COLOR_BLUE="\e[94m"
#################
### FUNCTIONS ###
#################
# Prints info message to shell
function info {
echo -e "$COLOR_LGRAY[${COLOR_BLUE}MINESTART${COLOR_LGRAY}][${COLOR_GREEN}INFO${COLOR_LGRAY}] $@$COLOR_DEFAULT"
}
# Prints error message to shell
function error {
echo -e "$COLOR_LGRAY[${COLOR_BLUE}MINESTART${COLOR_LGRAY}][${COLOR_RED}ERROR${COLOR_LGRAY}] $@$COLOR_DEFAULT"
}
# Prints warning message to shell
function warn {
echo -e "$COLOR_LGRAY[${COLOR_BLUE}MINESTART${COLOR_LGRAY}][${COLOR_YELLOW}WARN${COLOR_LGRAY}] $@$COLOR_DEFAULT"
}
# Checks, if package 'screen' is installed
#
# 1 = Package is installed
# 2 = Package is NOT installed
function isScreenInstalled {
screen -v &> /dev/null
if [[ $? -eq 1 ]]; then
echo 1
return
elif [[ $? -eq 127 ]]; then
echo 0
return
else
echo 0
return
fi
}
# 1 = Server is running
# 0 = Server is not running
function isRunning {
# At first, check if there is already a screen session
$(screen -ls | grep -q "$SCREEN_NAME")
if [[ $? -eq 0 ]]; then
echo 1
else
echo 0
fi
}
# This function returns the PID of the screen session $SCREEN_NAME
# (see definition at the top of this file)
function getScreenPid {
local SCREEN_PID=$(screen -ls | grep "$SCREEN_NAME" | grep -oEi "([0-9]+)\." | tr -d '.')
echo $SCREEN_PID
}
# Send the given arguments as command to the server
function doCmd {
if [[ -z $1 ]]; then
error "There is no command given to execute"
return
fi
if [[ $(isRunning) -eq 1 ]]; then
screen -S "$SCREEN_NAME" -p 0 -X stuff "$* $(printf \\r)"
else
error "There is no Server running with Screen Name '$SCREEN_NAME'"
fi
}
# Opens the console (screen session $SCREEN_NAME)
function openConsole {
if [[ $(isRunning) -eq 1 ]]; then
screen -r "$SCREEN_NAME"
else
error "There is no Server running with Screen Name '$SCREEN_NAME'"
fi
}
# Starts the Arriba - sim server
function startServer {
# Check if given EXE file is existing
if [[ ! -f $SERVER_EXE ]]; then
error "Could not find Server EXE file '$SERVER_EXE'"
error "Please set SERVER_EXE constant in $0"
exit 1
fi
local RUNNING=$(isRunning)
if [[ $RUNNING -eq 0 ]]; then
if [[ $JDK_INSTALLED -eq 1 ]]; then
screen -S "$SCREEN_NAME" -d -m mono "$SERVER_EXE"
local ERR_CODE=$?
if [[ $ERR_CODE -eq 0 ]]; then
# Save PID
local PID=$(getScreenPid)
echo $PID > "$SERVER_EXE.pid"
info "Starting Arriba - Sim Server ..."
info "Using Executable: $SERVER_EXE"
info "Process ID: $PID"
info "Server started successfully!"
else
error "Could not start Arriba - Sim Server (Error Code: $ERR_CODE)"
# Error Code 127 = Screen is not installed
if [[ $ERR_CODE -eq 127 ]]; then
error "You have to install the package 'screen'"
fi
fi
else
screen -S "$SCREEN_NAME" -d -m mono "$SERVER_EXE"
local ERR_CODE=$?
if [[ $ERR_CODE -eq 0 ]]; then
# Save PID
local PID=$(getScreenPid)
echo $PID > "$SERVER_EXE.pid"
info "Starting Arriba - Sim Server ..."
info "Using Executable: $SERVER_EXE"
info "Process ID: $PID"
info "Server started successfully!"
else
error "Could not start Arriba - Sim Server (Error Code: $ERR_CODE)"
# Error Code 127 = Screen is not installed
if [[ $ERR_CODE -eq 127 ]]; then
error "You have to install the package 'screen'"
fi
fi
fi
else
warn "The server is still running!"
warn "You can restart the script using 'restart'"
fi
}
# Stops the Arriba - sim server
function stopServer {
info "Stopping Arriba - Sim Server ($SCREEN_NAME)"
if [[ $(isRunning) -eq 0 ]]; then
warn "Server is NOT running!"
rm -Rf "$SERVER_EXE.pid"
return
else
doCmd "shutdown"
fi
local TRIES=0 # After 5 tries, error will be thrown
while sleep 1
info "Shutting down ..."
TRIES=$((TRIES+1))
if [[ $TRIES -ge 5 ]]; then
# Check running again and give feedback
if [[ $(isRunning) -eq 1 ]]; then
error "Stopping server failed! You should check the server log files"
return
else
info "Server was stopped successfully!"
return
fi
return
fi
do
# Only if the server is offline, remove the PID file
if [[ $(isRunning) -eq 0 ]]; then
rm -Rf "$SERVER_EXE.pid"
fi
done
}
# Prints the help message
function printHelp {
# Set color to white
echo -e "$COLOR_LGRAY"
printf "###########################\n"
printf "### ARRIBASTART v${VERSION} ###\n"
printf "###########################\n\n"
printf "Developed by Enrico Ludwig (Morph)\n\n"
printf "~$ whitestart [start|stop|restart|status|help|(Arriba command)] [(params)]\n\n"
printf "Examples:\n"
printf "1. ./arribastart.sh start (Starts the server from the current directory)\n"
printf "2. ./arribastart.sh stop (Stopps the server from the current directory)\n"
printf "3. ./arribastart.sh status (Prints the server status (online / offline))\n"
printf "4. ./arribastart.sh restart (Restarts the server from the current directory)\n"
printf "5. ./arribastart.sh reload (Reloads the server (alias for 'cmd reload')\n"
printf "6. ./arribastart.sh console (Opens the screen session with the server console)\n"
printf "7. ./arribastart.sh cmd [cmdname] {params} (Executes the given Server Command with optional arguments)\n"
printf "8. ./arribastart.sh help (Shows this help)\n\n"
printf "Questions? Ideas? Bugs? Contact me here: http://forum.mds-tv.de\n\n"
# Reset color to default
echo -e "$COLOR_DEFAULT"
exit
}
#####################
### FUNCTIONS END ###
#####################
# Check, if first Param is set, or print help if not
if [[ -z $1 ]]; then
printHelp
fi
# Check if screen is installed!
SCREEN_INSTALLED=$(isScreenInstalled)
if [[ $SCREEN_INSTALLED -eq 0 ]]; then
error "You have to install the package 'screen'"
error "On Debian based Systems (like Ubuntu) you can do: 'apt-get install screen'"
error "On RedHat based Systems (like CentOS) you can do: 'yum install screen'"
exit 1
fi
# Server control
case "$1" in
"start")
startServer
;;
"stop")
stopServer
;;
"restart")
stopServer
startServer
;;
"status")
if [[ $(isRunning) -eq 1 ]]; then
info "The Server with screen name '$SCREEN_NAME' is running!"
else
info "The Server with screen name '$SCREEN_NAME' is NOT running!"
fi
;;
"cmd")
doCmd ${@:2}
;;
"reload")
doCmd "reload"
;;
"console")
if [[ $(isRunning) -eq 1 ]]; then
info "Entering Server Console"
openConsole
info "Exiting Server Console"
else
error "The Server with screen name '$SCREEN_NAME' is NOT running!"
fi
;;
"help")
printHelp
;;
*)
error "Unknown command '$1'"
;;
esac
Und hier die Quelle wo ich das Script bekomme hab.
RE: Startscript für OpenSim etc - Dorena Verne - 02.07.2014
Feine Sache.
Du hast aber vergessen zu erwähnen,..das dieses ausschließlich für Linux gemacht ist.
RE: Startscript für OpenSim etc - Bogus Curry - 02.07.2014
naja unter Windows braucht man ja so ein Script ja nicht *gg
RE: Startscript für OpenSim etc - Bogus Curry - 22.02.2016
Hallo zusammen ;D
Hab hier noch ein StartScript für OpenSim gefunden, nicht von mir getestet ...
Code: #!/bin/bash
#
# for usage, run without arguments
#
# see ../README for setup instructions.
#
# Original code by Dave Coyle (http://coyled.com)
# Tweaks by Gwyneth Llewelyn (http://gwynethllewelyn.net/)
# Requires bash 4
# The original script assumed that you‘d be running one sim per instance,
# and launch a different script per sim.
# These changes assume you have multiple instances with multiple sims,
# and that instance names are launched all from the same place with
# an unique identification for each
# List of valid instances. Make sure you add all of your instances here
declare -A instances
for index in <Region 1> <Region 2> <Region x>
do
instances[$index]=1
done
show_help() {
echo "Input: opensim {start|stop|open|restart|console} "
echo -n " for following Regions: "
echo ${!instances[*]}
}
# Change <opensim_user> with your valid opensim user
check_user() {
if [ $USER != '<opensim_user>' ]; then
echo "Only <opensim_user> is allowed to use the script"
exit 1
fi
}
setup() {
if [ ! $1 ]; then
show_help
exit 1
else
SIM=$1
fi
# Change the directories inline with your installation directories
# The pid_dir must be set to the value, you used in OpenSim.exe.config
# within your regions path
if [[ ${instances[$SIM]} ]]; then
MONO="mono"
OPENSIM_DIR="/put/your/opensim_dir/here"
PID="$OPENSIM_DIR/put/your/pid_dir/here${SIM}/${SIM}.pid"
SCREEN="screen"
GRID_DIR="./<grid_dir>"
# set GRID_DIR to the subdirectory where your individual
# instance configuration is
else
echo "Region ${SIM} is unknown. Exit."
exit 1;
fi
}
do_start() {
if [ ! $1 ]; then
show_help
exit 1
else
SIM=$1
fi
setup $SIM
check_user
cd ${OPENSIM_DIR}/bin && $SCREEN -S $SIM -d -m -l $MONO OpenSim.exe -hypergrid=true -inidirectory="$GRID_DIR/$SIM" -logconfig="$GRID_DIR/$SIM/OpenSim.exe.config"
}
do_kill() {
if [ ! $1 ]; then
show_help
exit 1
else
SIM=$1
fi
setup $SIM
check_user
if [ -f $PID ]; then
kill -9 `cat $PID`
else
echo "Region ${SIM} PID not found."
exit 1
fi
}
do_console() {
if [ ! $1 ]; then
show_help
exit 1
fi
setup $1
cd ${OPENSIM_DIR}/bin && $SCREEN -S $SIM -d -m -l $MONO OpenSim.exe -hypergrid=true -inidirectory="$GRID_DIR/$SIM" -logconfig="$GRID_DIR/$SIM/OpenSim.exe.config"
}
do_open() {
if [ ! $1 ]; then
show_help
exit 1
else
SIM=$1
fi
setup $SIM
check_user
if [ -f $PID ]; then
screen -r $SIM
else
echo "Region ${SIM} PID not found."
exit 1
fi
}
case "$1" in
start)
do_start $2
;;
stop)
do_kill $2
;;
open)
do_open $2
;;
kill)
do_kill $2
;;
restart)
do_kill $2
do_start $2
;;
console)
do_console $2
;;
*)
show_help
exit
;;
esac
[*]
Quelle: http://www.3dgrid.de/index.php/tech/78-opensim-start
|