Smart Prestart LINUX

From OpenSimulator

(Difference between revisions)
Jump to: navigation, search
(page positioning changed - this page will be the subpage of Automating Tasks)
Line 1: Line 1:
 +
{{Template:Quicklinks}}
 
As most of you are aware, this can be quite a tedious chore to start multiple instances, back them up, shut them down. Being an Automation type, I created the following scripts to help others who are tired of the tedious aspects.  
 
As most of you are aware, this can be quite a tedious chore to start multiple instances, back them up, shut them down. Being an Automation type, I created the following scripts to help others who are tired of the tedious aspects.  
  
Line 312: Line 313:
 
----
 
----
  
'''BACK-LINKS'''
+
Return to [[Automating Tasks]]
 
+
== Windows  ==
+
 
+
[[Smart Prestart WIN]] [[Backing Up WIN]] [[Automated Upgrade WIN]]
+
 
+
== Linux  ==
+
 
+
[[Smart_Prestart_LINUX]] [[Backing Up LINUX]] [[Automated Upgrade LINUX]]
+

Revision as of 20:34, 2 January 2011

As most of you are aware, this can be quite a tedious chore to start multiple instances, back them up, shut them down. Being an Automation type, I created the following scripts to help others who are tired of the tedious aspects.

The usage of this requires BASH as they are BASH scripts and server console scripts. I used BASH because it is common to all distro's of Linux and therefore the most portable but as we know, even that is subject to slight variations, so therefore I cannot guarantee that this will work on your distro but they should be adaptable. These were developed and tested on Centos 5.3 with MONO 2.5 (no mono dependency at all).
SPECIAL NOTE !! I use SCREEN as the shell to run the OpenSim Instances, therefore these scripts communicate / use SCREEN

DISCLAIMER: I do not guarantee complete operation OR compatibility on all distro's. I accept NO RESPONSIBILITY for their use or issues resulting from their use.
LICENSE / USAGE: do whatever, use however, AS IS / WHEREIS. Fully Open to use, modify, fold, spindle, mutilate & staple. IF you improve or Optimize the materials presented here, it would be certainly appreciated if you post those changes / mods so that others can benefit from them.

I am gonna start with the BASH scripts for Linux, then the Console Scripts for the OpenSim Server.
!!! THIS IS A SUITE OF SCRIPTS THAT WORK TOGETHER !!!

  1. 1 -Start_OS.sh
  • This will startup Multiple Instances of OpenSim.
  • Creates a Backup Structure and backs up critical information
  • Backs up SqlLite / MySql databases
  • Packages everything into a TAR.GZ
  • Read the Header for detailed information.

Command to execute = bash Start_OS.sh


#!/bin/bash
#
# FILENAME: Start_OS.sh
# AUTHOR: WhiteStar Magic @ OSGrid
# DATE: August.20.2009
# REVISION: 1.0 (initial release)
#
# DESCRIPTION: Starts OpenSim.exe with some pre-processing
# - Checks to see if Backup folders exist and if not creates backup folder structures (see MAKE_dirs)
# - copies opensim.log from /BIN folder to Log Backup & renames it to OSLOG_Date-time.log
# - example of output OSLOG_16082009-1008.log
# - then it CLEARS the log to EMPTY in the /BIN folder so you can see everything from startup
# - WHY? Easier to track startup issues / debugging and helps reduce size of live opensim.log
# - Copies out Several key pieces of data and stores them in the /INSTANCE/BACKup Structure
# - Copies out *.DB files (SqlLite) into the BACKup/DB directory
# - Performs a MySql Dump to BACKup/DBsql of the MySql Databases **
# ** Handles Multiple MySql DB's or Single opensim db. See Section for detailed explanation
# 
# INSTALLATION:
# copy this script into /opt and run with the following command bash Start_OS.sh
# can be installed in another directory, Adjust the script accordingly
#
# The following need to be configured within the script for EVERY INSTANCE: (detailed comments in FIRST INSTANCE)
#
# OSInstance="/opensim/instance_1" <- Location of your OpenSim Instance
# OSbackup="/BACKup" <- Root Directory for Backup Structure ("/opensim/instance_1/BACKup")
# DBusr="DATABASE_USER_NAME" <- User Name for MySql DB Access (leave blank if using SqlLite)
# DBpw="DATABASE_PASSWORD" <- Password for MySql DB Access " "
# DBname="opensim" <- Database Name for MySql " " 
# 
# KUDOS & THANKS: 
# Thanks a LOT to the following individuals @ OSGrid 
# Coyled, BWild, Godfrey, Hiro, DeneSparta and the rest of the gang! THANKS GUYS !
# An Excellent Resource for anyone interested in BASH scripting: http://tldp.org/LDP/abs/html/
#
# -------------------------------------------------------------------------------------------------
# OSbackup = Where you want your Backup File Structure to be and send files to
# This will create the structure as: /INSTANCENAME/BACKup with the complete Sub-Structure beneath it
#
OSbackup="/BACKup"
echo OSbackup = $OSbackup
# --------------------------------------------------------------------------------------
# DATE & TIME String Assembly
# --------------------------------------------------------------------------------------
# Date & Time Format on your system
# 
# date %F = (%Y%m%d)
# date %H = 24 hr, %M - Minutes
# 
TimeStamp=`date +%d%m%Y-%H%M`
# we now have a string which will appear as 16082009-1008
# --------------------------------------------------------------------------------------
echo TimeStamp = $TimeStamp
# ---------------------------------------------------------------------------------------
# === Make Backup Folders function ===
MAKE_dirs()
{
echo Error: Backup Folders do not exist, Creating structure
mkdir -v ${OSInstance}${OSbackup}
mkdir -v ${OSInstance}${OSbackup}/DB
mkdir -v ${OSInstance}${OSbackup}/DBsql
mkdir -v ${OSInstance}${OSbackup}/INI
mkdir -v ${OSInstance}${OSbackup}/EXPORTS
mkdir -v ${OSInstance}${OSbackup}/LOGS
mkdir -v ${OSInstance}${OSbackup}/OAR
mkdir -v ${OSInstance}${OSbackup}/REGIONS
mkdir -v ${OSInstance}${OSbackup}/TERRAINS
mkdir -v ${OSInstance}${OSbackup}/TXT
mkdir -v ${OSInstance}${OSbackup}/XML2
sleep 3
# Sleeps for 3 seconds to allow for server to update properly
}
#
# ---------------------------------------------------------------------------------------
# === File Copy & Archiving Function ===
COPY_files()
{
# copy log file over
cp ${OSInstance}/bin/OpenSim.log ${OSInstance}${OSbackup}/LOGS/OpenSim.log
mv ${OSInstance}${OSbackup}/LOGS/OpenSim.log ${OSInstance}${OSbackup}/LOGS/OSlog_${TimeStamp}.log
# 
# NEXT FLUSHING LOG to EMPTY
echo LOG_CLEARED AT ${TimeStamp} > ${OSInstance}/bin/OpenSim.log
# 
# NEXT copy out the estate info from /bin
cp ${OSInstance}/bin/estate_settings.xml ${OSInstance}${OSbackup}/LOGS/estate_settings.xml
#
# NEXT we copy the *.DB files for SqlLite IF they are in use. These all have DB extension
rsync -r --prune-empty-dirs --progress --filter '+ *.db' --filter '+ */' --filter '- *' ${OSInstance}/bin/* ${OSInstance}${OSbackup}/DB/
#
# NEXT we get MySql DB Dump
if [ ${DBusr}tst != "tst" ]; then
echo MySql DB Backup of ${DBname} being processed
mysqldump --opt -u${DBusr} -p${DBpw} ${DBname} > ${OSInstance}${OSbackup}/DBsql/${DBname}.sql
fi;
#
# copying ALL txt files over (safety precaution if you have console scripts or other text files located in /BIN+ folders)
rsync -r --prune-empty-dirs --progress --filter '+ *.txt' --filter '+ */' --filter '- *' ${OSInstance}/TXT/* 
#
# copying ALL ini files over
rsync -r --prune-empty-dirs --progress --filter '+ *.ini' --filter '+ */' --filter '- *' ${OSInstance}/bin/* ${OSInstance}${OSbackup}/INI/
#
# copy regions files over 
cp -r -u -p ${OSInstance}/bin/Regions/*.* ${OSInstance}${OSbackup}/REGIONS
#
# copy exports files over 
cp -r -u -p ${OSInstance}/bin/exports/* ${OSInstance}${OSbackup}/EXPORTS
#
# MAKE A TAR.GZ Compressed FILE of the backup data. Delete previous one, generate new one with TimeStamp
rm -f ${OSInstance}${OSbackup}/BACKUP_*.tar.gz 
tar --create --gzip --file=${OSInstance}${OSbackup}/BACKUP_${TimeStamp}.tar.gz ${OSInstance}${OSbackup}/*
}
#
# =====================================
# === NOW for the Instance Startups ===
# =====================================
# === COMMENTED READ CAREFULLY ===
# =====================================
# --- FIRST INSTANCE ---
#
# --- set pathing next
# OSInstance = Where the OpenSim Instance is installed, SET AT EVERY INSTANCE
# This is NOT the BIN Folder. It is one folder ABOVE the /bin
#
OSInstance="/opensim/INSTANCE_1"
#
# --- MySql Database Information to backup MySql DataBase ---
# !!! NOTE !!! By Default only ONE database is used "opensim" so only make one backup
# Some Installations have a unique DB for each instance so backup individual DB's
# The following info is located in your OpenSim.ini where you configured MySql Databases, See Next Line Example.
# storage_connection_string="Data Source=localhost;Database=opensim;User ID=root;Password=***password***;";
# DBusr = MySql DB User Name, default = root (not recomended)
# DBpwd = MySql DB Password, for the user account
# DBname= MySql Database Name, default is usually "opensim"
# The Following Variables MUST be set for each instance IF unique DB's are running.
# IF you only have ONE DB "opensim" Blank the variables AFTER the first backup
#
DBusr="DATABASE_USER_NAME"
DBpw="DATABASE_PASSWORD" 
DBname="opensim"
#
echo OSInstance = $OSInstance
cd ${OSInstance}
#
# --- test to see if backup folders exist, if not make them
if [ ! -e "${OSInstance}${OSbackup}" ]; then MAKE_dirs; fi
#
# --- Process & Copy important files
COPY_files
# 
# STARTING OPENSIM
# change directory to /bin to make sure and startup system as usual
cd ${OSInstance}/bin
echo we are are starting up OPENSIM Instance in ${OSInstance}/bin 
# Start Screen commands
# -d Detach the elsewhere running screen (and reattach here).
# -m ignore $STY variable, do create a new screen session.
# INSTANCE_* = Descriptive name for the SCREEN for identification
#
screen -S INSTANCE_1 -d -m mono OpenSim.exe -gui=true
# screen -S INSTANCE_1 -d -m mono OpenSim.32BitLaunch.exe -gui=true
#
# NOTE !! USE "OpenSim.32BitLaunch.exe" if running on 64-bit Operating system
sleep 3
#
# sleep is here because systems need a bit of time to not overload the server
# Adjust according to need
# -----------------------
# --- SECOND INSTANCE ---
#
OSInstance="/opensim/INSTANCE_2"
DBusr="DATABASE_USER_NAME"
DBpw="DATABASE_PASSWORD"
DBname="opensim"
cd ${OSInstance}
#
if [ ! -e "${OSInstance}${OSbackup}" ]; then MAKE_dirs; fi
#
COPY_files
#
cd ${OSInstance}/bin
echo we are are starting up OPENSIM Instance in ${OSInstance}/bin 
screen -S INSTANCE_2 -d -m mono OpenSim.exe -gui=true
# screen -S INSTANCE_2 -d -m mono OpenSim.32BitLaunch.exe -gui=true
sleep 3
# ----------------------
# --- THIRD INSTANCE ---
#
OSInstance="/opensim/INSTANCE_3"
DBusr="DATABASE_USER_NAME"
DBpw="DATABASE_PASSWORD" 
DBname="opensim"
cd ${OSInstance}
#
if [ ! -e "${OSInstance}${OSbackup}" ]; then MAKE_dirs; fi
#
COPY_files
#
cd ${OSInstance}/bin
echo we are are starting up OPENSIM Instance in ${OSInstance}/bin 
screen -S INSTANCE_3 -d -m mono OpenSim.exe -gui=true
# screen -S INSTANCE_3 -d -m mono OpenSim.32BitLaunch.exe -gui=true
sleep 3
#
# === END of Server-2 Startup Processing
# --- show the screen list to verify that the instances are all running as they should be. 
screen -ls 
sleep 10


BASH SCRIPT to Auto Shutdown Multiple Instances

  • Inserts an alert message into Screen for the CONSOLE to send, with 2 minutes wanrning to users logged into regions on the instances.
  • Inserts shutdown command into Screen for the CONSOLE to execute. "Clean & Proper shutdown"
  • Could be adapted for many other functions and initiated by a chron call

Command to execute = bash Close_OS.sh


#!/bin/sh 
#
# Script Name: Close_OS.sh
# Author: WhiteStar Magic @ OSGRID
# Date: August 20,2009
#
# Purpose: 
# Automated shutdown of multiple instances running on Linux under SCREEN.
# This warns people That a shutdown is coming in all running instances & their regions
# Then after the timer is complete, it stuffs a shutdown command into the opensim instance
# for a proper clean shutdown. This CAN take time, be patient
#
# TO USE:
# run following command " bash Close_OS.sh "
#
# dependencies:
# Requires that 2 Variables MUST be set. 
# 1) = CONmsg = Console message to users
# 2) = CONcmd = Console Command to issue
# NOTE: ^M = Return, needs to be sent with message to be executed
#
# NOTE: Sleep is given in 2 seconds for notifications delay. Allows server to buffer
# POST notification sleep is 2 minutes to allow users to vacate
# 
# Adjust the following lines to suit purpose
# NOTE CONmsg "alert general" is the Console Command to Broadcast msg to all regions within the instance
#
CONmsg="alert general Server Shutdown in 2 minutes, Please Relocate or Logout"
CONcmd="shutdown"
# -------------------------------------
# --- Instance Notification Process ---
notify()
{
echo Notifying ${instance} of ${CONmsg}
screen -d -r ${instance} -X stuff "$CONmsg"
screen -d -r ${instance} -X eval "stuff ^M"
}
# -------------------------
# --- COMMAND Process ---
command()
{
echo Shutting Down ${instance} 
screen -d -r ${instance} -X stuff "$CONcmd"
screen -d -r ${instance} -X eval "stuff ^M"
}
# ----------------------------------------
# === NOTIFY Instances & their REGIONS ===
#
instance="INSTANCE_1"
notify
#
instance="INSTANCE_2"
notify
#
instance="INSTANCE_3"
notify
#
# ---------------------------------------------
# ==== SLEEP TILL READY TO EXECUTE SHUTDOWN ===
# sleeping for 2 minutes, adjust as needed, in seconds
sleep 120 
#
# --------------------------
# === SHUTDOWN INSTANCES ===
#
instance="INSTANCE_1"
command
#
instance="INSTANCE_2"
command
#
instance="INSTANCE_3"
command
#
# !!! End of Shutdown processing, wait till all instances are down. 
# Some may take time to save and close out.
#

 


Return to Automating Tasks

Personal tools
General
About This Wiki