User talk:OtakuMegane
From OpenSimulator
(Difference between revisions)
OtakuMegane (Talk | contribs) (→Modified oswatchdog for multiple instances) |
OtakuMegane (Talk | contribs) m (derp) |
||
(5 intermediate revisions by one user not shown) | |||
Line 1: | Line 1: | ||
− | == | + | == Opensim Status == |
− | This is | + | This is the script I use to monitor my Opensim instances and restart them as needed. Originally based on BlueWall's oswatchdog script. |
− | + | NOTE: This assumes you have separate script(s) to launch each instance | |
− | <source lang="bash"> | + | <source lang="bash"> |
− | #! /bin/sh | + | #!/bin/sh |
# | # | ||
# THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | # THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
Line 16: | Line 16: | ||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
# | # | ||
# | # | ||
# Base opensim installation | # Base opensim installation | ||
− | BASE=" | + | BASE="" |
# Log | # Log | ||
Line 33: | Line 25: | ||
# Hostname | # Hostname | ||
− | HOSTNAME=" | + | HOSTNAME="" |
+ | |||
+ | # If you run this script as root but opensim is run under another user, set this to TRUE. | ||
+ | # Otherwise ignore it | ||
+ | RUN_AS_OTHER_USER='FALSE' | ||
#if the file exist, opensim wont be restarted | #if the file exist, opensim wont be restarted | ||
Line 39: | Line 35: | ||
LOCKFILE="/tmp/norun.opensim" | LOCKFILE="/tmp/norun.opensim" | ||
− | if [ -f "$LOCKFILE" ] | + | if [ -f "$LOCKFILE" ] |
+ | then | ||
echo $LOCKFILE "found. no restart" | echo $LOCKFILE "found. no restart" | ||
exit | exit | ||
fi | fi | ||
+ | |||
+ | terminate_dead() | ||
+ | { | ||
+ | kill -KILL $1 | ||
+ | sleep 3 | ||
+ | } | ||
status_check() | status_check() | ||
{ | { | ||
running_pid=`ps ax|grep $2|grep -v grep|tr -s ' '|sed 's/^ //'|cut -f1 -d' '` | running_pid=`ps ax|grep $2|grep -v grep|tr -s ' '|sed 's/^ //'|cut -f1 -d' '` | ||
− | if [ -z "$running_pid" ] | + | screen_is_dead=`screen -list|grep $2|tr -s ' '|grep '(Dead ???)'` |
+ | |||
+ | if [ -n "$screen_is_dead" ] | ||
+ | then | ||
+ | screen -wipe | ||
+ | fi | ||
+ | |||
+ | if ! curl "http://$HOSTNAME:$1/simstatus/" > /dev/null 2>&1 | ||
+ | then | ||
+ | if [ -n "$running_pid" ] | ||
+ | then | ||
+ | terminate_dead $running_pid | ||
+ | fi | ||
+ | fi | ||
+ | |||
+ | if [ -z "$running_pid" ] | ||
+ | then | ||
#...We Make A Log Entry And Start A New One | #...We Make A Log Entry And Start A New One | ||
# The Log Entry | # The Log Entry | ||
TIME="Simulator $2 Down, Restarting: `/bin/date +"%A, %B %d - %r"`" | TIME="Simulator $2 Down, Restarting: `/bin/date +"%A, %B %d - %r"`" | ||
echo $TIME >>$LOG | echo $TIME >>$LOG | ||
− | + | ||
− | + | if [ $RUN_AS_OTHER_USER = 'TRUE' ] | |
− | if | + | |
then | then | ||
− | + | su -l $4 -c "$3" | |
+ | else | ||
+ | $3 | ||
fi | fi | ||
+ | |||
+ | echo "$2 was down or unresponsive. Restarted." | ||
+ | else | ||
+ | echo "$2 is up and responds with OK status." | ||
fi | fi | ||
} | } | ||
Line 65: | Line 89: | ||
# values for the instance. | # values for the instance. | ||
# | # | ||
− | # listener port | + | # status_check "<listener port>" "<screen name>" "<launch script>" "<user>" |
− | + | ||
− | + | ||
# | # | ||
− | # | + | # <listener port> - The port the instance listens to. Is set in OpenSim.ini; default is 9000 |
+ | # <screen name> - The name of the screen running the instance | ||
+ | # <launch script> - The filename of the script that launches the instance | ||
+ | # <user> - User that opensim runs under. Unless you set RUN_AS_OTHER_USER='TRUE' this will be ignored | ||
# | # | ||
+ | # Example: status_check "9000" "OpensimOne" "/home/opensim/opensim-one.sh" "opensim" | ||
− | status_check "<listener port>" "<screen name>" "<launch script>" | + | status_check "<listener port>" "<screen name>" "<launch script>" "<user>" |
</source> | </source> |
Latest revision as of 16:17, 13 July 2016
[edit] Opensim Status
This is the script I use to monitor my Opensim instances and restart them as needed. Originally based on BlueWall's oswatchdog script.
NOTE: This assumes you have separate script(s) to launch each instance
#!/bin/sh # # THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # # Base opensim installation BASE="" # Log LOG="$BASE/status-log.log" # Hostname HOSTNAME="" # If you run this script as root but opensim is run under another user, set this to TRUE. # Otherwise ignore it RUN_AS_OTHER_USER='FALSE' #if the file exist, opensim wont be restarted # Sacha Magne LOCKFILE="/tmp/norun.opensim" if [ -f "$LOCKFILE" ] then echo $LOCKFILE "found. no restart" exit fi terminate_dead() { kill -KILL $1 sleep 3 } status_check() { running_pid=`ps ax|grep $2|grep -v grep|tr -s ' '|sed 's/^ //'|cut -f1 -d' '` screen_is_dead=`screen -list|grep $2|tr -s ' '|grep '(Dead ???)'` if [ -n "$screen_is_dead" ] then screen -wipe fi if ! curl "http://$HOSTNAME:$1/simstatus/" > /dev/null 2>&1 then if [ -n "$running_pid" ] then terminate_dead $running_pid fi fi if [ -z "$running_pid" ] then #...We Make A Log Entry And Start A New One # The Log Entry TIME="Simulator $2 Down, Restarting: `/bin/date +"%A, %B %d - %r"`" echo $TIME >>$LOG if [ $RUN_AS_OTHER_USER = 'TRUE' ] then su -l $4 -c "$3" else $3 fi echo "$2 was down or unresponsive. Restarted." else echo "$2 is up and responds with OK status." fi } # Add a new line for each instance you want to monitor. # All you need to do is replace each of the three settings with the correct # values for the instance. # # status_check "<listener port>" "<screen name>" "<launch script>" "<user>" # # <listener port> - The port the instance listens to. Is set in OpenSim.ini; default is 9000 # <screen name> - The name of the screen running the instance # <launch script> - The filename of the script that launches the instance # <user> - User that opensim runs under. Unless you set RUN_AS_OTHER_USER='TRUE' this will be ignored # # Example: status_check "9000" "OpensimOne" "/home/opensim/opensim-one.sh" "opensim" status_check "<listener port>" "<screen name>" "<launch script>" "<user>"