aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/scripts
diff options
context:
space:
mode:
authoronefang2019-05-22 19:14:35 +1000
committeronefang2019-05-22 19:14:35 +1000
commitca7a2ed839f8fec5a7d7abbf50fc2c031f192fb5 (patch)
tree9b4dfc525c31a88014a8d7d6c223e7cd452749c6 /scripts
parentRenamed branch to SledjChisl. (diff)
downloadopensim-SC_OLD-ca7a2ed839f8fec5a7d7abbf50fc2c031f192fb5.zip
opensim-SC_OLD-ca7a2ed839f8fec5a7d7abbf50fc2c031f192fb5.tar.gz
opensim-SC_OLD-ca7a2ed839f8fec5a7d7abbf50fc2c031f192fb5.tar.bz2
opensim-SC_OLD-ca7a2ed839f8fec5a7d7abbf50fc2c031f192fb5.tar.xz
Major tweaking of the scripts to suit the new setup.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/backup-sims.sh4
-rwxr-xr-xscripts/common.sh3
-rwxr-xr-xscripts/install/create_sim.sh55
-rwxr-xr-xscripts/install/go_live.sh2
-rw-r--r--scripts/install/opensim-monit.conf17
-rwxr-xr-xscripts/install/secure.sh20
-rwxr-xr-xscripts/start-sim18
7 files changed, 66 insertions, 53 deletions
diff --git a/scripts/backup-sims.sh b/scripts/backup-sims.sh
index b14acca..cadb9a2 100755
--- a/scripts/backup-sims.sh
+++ b/scripts/backup-sims.sh
@@ -6,9 +6,9 @@ getPrgDir
6for i in $(seq -w 1 99) 6for i in $(seq -w 1 99)
7do 7do
8 j=$(num2name ${i}) 8 j=$(num2name ${i})
9 if [ -e "${PRGDIR}/../config/${j}" ] 9 if [ -e "${PRGDIR}/../../config/${j}" ]
10 then 10 then
11 pushd ${PRGDIR}/../config/${j} >/dev/null 11 pushd ${PRGDIR}/../../config/${j} >/dev/null
12 # Find out the size of the last backup, base our later sleep on that, but do it now before backup-sim packs it away. 12 # Find out the size of the last backup, base our later sleep on that, but do it now before backup-sim packs it away.
13 sizeSleep=`sleepPerSize o "$(getSimName ${i})"` 13 sizeSleep=`sleepPerSize o "$(getSimName ${i})"`
14 ./backup-sim 14 ./backup-sim
diff --git a/scripts/common.sh b/scripts/common.sh
index 2ec19ce..c5a86ab 100755
--- a/scripts/common.sh
+++ b/scripts/common.sh
@@ -1,5 +1,7 @@
1#!/bin/echo Don't run this file, it's for common functions." 1#!/bin/echo Don't run this file, it's for common functions."
2 2
3OS_PATH="/opt/opensim_SC"
4OS_USER="opensimsc"
3 5
4# Figure out where we are, most of this mess is to troll through soft links. 6# Figure out where we are, most of this mess is to troll through soft links.
5# PRGDIR=$(getPrgDir) 7# PRGDIR=$(getPrgDir)
@@ -73,4 +75,3 @@ sleepPerSize()
73 echo 200 75 echo 200
74 fi 76 fi
75} 77}
76
diff --git a/scripts/install/create_sim.sh b/scripts/install/create_sim.sh
index 0681067..08cedba 100755
--- a/scripts/install/create_sim.sh
+++ b/scripts/install/create_sim.sh
@@ -1,6 +1,6 @@
1#!/bin/bash 1#!/bin/bash
2 2
3source common.sh 3source ../common.sh
4getPrgDir 4getPrgDir
5 5
6NAME=$1 6NAME=$1
@@ -9,8 +9,7 @@ URL=$3
9IP=$4 9IP=$4
10SIZE=$5 10SIZE=$5
11 11
12OSPATH="/opt/opensim" 12cd ${OS_PATH}/config
13cd $OSPATH/config
14 13
15k=0 14k=0
16for i in $(seq -w 1 99) 15for i in $(seq -w 1 99)
@@ -22,38 +21,37 @@ do
22 fi 21 fi
23done 22done
24 23
25if [ "x$NAME" = "x" ] 24if [ "x${NAME}" = "x" ]
26then 25then
27 NAME="No name sim $RANDOM" # Should be unique per grid. 26 NAME="No name sim $RANDOM" # Should be unique per grid.
28 echo "WARNING setting the sim name to [$NAME], this may not be what you want." 27 echo "WARNING setting the sim name to [${NAME}], this may not be what you want."
29fi 28fi
30# Sanitize the name. Not removing [ or ], couldn't get that to work, only important for Windows. 29# Sanitize the name. Not removing [ or ], couldn't get that to work, only important for Windows.
31sim=$(sanitize $NAME) 30sim=$(sanitize ${NAME})
32 31
33if [ "x$LOCATION" = "x" ] 32if [ "x${LOCATION}" = "x" ]
34then 33then
35 LOCATION="$RANDOM,$RANDOM" # again UNIQUE (i.e. ONLY ONE) per grid in THIS case! 34 LOCATION="$RANDOM,$RANDOM" # again UNIQUE (i.e. ONLY ONE) per grid in THIS case!
36 echo "WARNING setting the Location to $LOCATION, this may not be what you want." 35 echo "WARNING setting the Location to ${LOCATION}, this may not be what you want."
37fi 36fi
38 37
39if [ "x$IP" = "x" ] 38if [ "x${IP}" = "x" ]
40then 39then
41 # 0.0.0.0 will work for a single sim per physical machine, otherwise we need the real internal IP.
42 IP="0.0.0.0" 40 IP="0.0.0.0"
43 echo "WARNING setting the InternalAddress to $IP, this may not be what you want." 41 echo "WARNING setting the InternalAddress to ${IP}, this may not be what you want."
44# echo " 0.0.0.0 will work for a single sim per physical machine, otherwise we need the real internal IP." 42# echo " 0.0.0.0 will work for a single sim per physical machine, otherwise we need the real internal IP."
45# According to the OpenSim docs, 0.0.0.0 means to listen on all NICs the machine has, which should work fine. 43# According to the OpenSim docs, 0.0.0.0 means to listen on all NICs the machine has, which should work fine.
46fi 44fi
47 45
48if [ "x$URL" = "x" ] 46if [ "x${URL}" = "x" ]
49then 47then
50# Here we make use of an external IP finding service. Careful, it may move. 48# Here we make use of an external IP finding service. Careful, it may move.
51# URL=$(wget -q http://automation.whatismyip.com/n09230945.asp -O -) # URL is best (without the HTTP://), but IP (e.g. 88.109.81.55) works too. 49# URL=$(wget -q http://automation.whatismyip.com/n09230945.asp -O -) # URL is best (without the HTTP://), but IP (e.g. 88.109.81.55) works too.
52 URL="SYSTEMIP" 50 URL="SYSTEMIP"
53 echo "WARNING setting the ExternalHostName to $URL, this may not be what you want." 51 echo "WARNING setting the ExternalHostName to ${URL}, this may not be what you want."
54fi 52fi
55 53
56if [ "x$SIZE" = "x" ] 54if [ "x${SIZE}" = "x" ]
57then 55then
58 SIZE="256" 56 SIZE="256"
59fi 57fi
@@ -68,29 +66,30 @@ fi
68PORT=$(( 9005 + (10#$k * 5) )) # 9002 is used for HTTP/UDP so START with port 9003! CAUTION Diva/D2 starts at port 9000. 66PORT=$(( 9005 + (10#$k * 5) )) # 9002 is used for HTTP/UDP so START with port 9003! CAUTION Diva/D2 starts at port 9000.
69UUID=$(uuidgen) 67UUID=$(uuidgen)
70 68
71echo "Creating sim$NUM on port $PORT @ $LOCATION - $NAME." 69echo "Creating sim${NUM} on port ${PORT} @ ${LOCATION} - ${NAME}."
72 70
73cp -r sim_skeleton sim$NUM 71cp -r sim_skeleton sim${NUM}
74 72
75cd sim$NUM 73cd sim${NUM}
76mv My_sim.xml ${sim}.xml 74mv My_sim.xml ${sim}.xml
77sed -i "s@SIM_NAME@$NAME@g" ${sim}.xml 75sed -i "s@SIM_NAME@${NAME}@g" ${sim}.xml
78sed -i "s@SIM_UUID@$UUID@g" ${sim}.xml 76sed -i "s@SIM_UUID@${UUID}@g" ${sim}.xml
79sed -i "s@SIM_POS@$LOCATION@g" ${sim}.xml 77sed -i "s@SIM_POS@${LOCATION}@g" ${sim}.xml
80sed -i "s@SIM_IP@$IP@g" ${sim}.xml 78sed -i "s@SIM_IP@${IP}@g" ${sim}.xml
81sed -i "s@SIM_INT_PORT@$(( $PORT + 1 ))@g" ${sim}.xml 79sed -i "s@SIM_INT_PORT@$(( ${PORT} + 1 ))@g" ${sim}.xml
82sed -i "s@SIM_URL@$URL@g" ${sim}.xml 80sed -i "s@SIM_URL@${URL}@g" ${sim}.xml
83sed -i "s@SIM_SIZE@$SIZE@g" ${sim}.xml 81sed -i "s@SIM_SIZE@${SIZE}@g" ${sim}.xml
84 82
85ln -s ../../current/scripts/common.sh common.sh 83ln -s ../../current/scripts/common.sh common.sh
86ln -s ../../current/scripts/start-sim start-sim 84ln -s ../../current/scripts/start-sim start-sim
87cp -P start-sim backup-sim 85cp -P start-sim backup-sim
88cp -P start-sim stop-sim 86cp -P start-sim stop-sim
89 87
90sed -i "s@SIM_NUMBER@$NUM@g" ThisSim.ini 88sed -i "s@SIM_NUMBER@${NUM}@g" ThisSim.ini
91sed -i "s@SIM_PORT@$PORT@g" ThisSim.ini 89sed -i "s@SIM_PORT@${PORT}@g" ThisSim.ini
92 90
93sed -i "s@SIM_NUMBER@$NUM@g" opensim-monit.conf 91sed -i "s@OS_PATH@${OS_PATH}@g" opensim-monit.conf
92sed -i "s@SIM_NUMBER@${NUM}@g" opensim-monit.conf
94 93
95sudo chown -R opensim:opensim .. 94sudo chown -R ${OS_USER}:${OS_USER} ..
96sudo chmod -R g+w .. 95sudo chmod -R g+w ..
diff --git a/scripts/install/go_live.sh b/scripts/install/go_live.sh
index 21d7072..c5ce90e 100755
--- a/scripts/install/go_live.sh
+++ b/scripts/install/go_live.sh
@@ -1,6 +1,6 @@
1#!/bin/bash 1#!/bin/bash
2 2
3OSPATH="/opt/opensim" 3source common.sh
4 4
5for i in $(seq 99) 5for i in $(seq 99)
6do 6do
diff --git a/scripts/install/opensim-monit.conf b/scripts/install/opensim-monit.conf
index 7785056..409b69e 100644
--- a/scripts/install/opensim-monit.conf
+++ b/scripts/install/opensim-monit.conf
@@ -9,23 +9,16 @@
9# on ubuntu/debian, this is overridden by the CHECK_INTERVALS var in 9# on ubuntu/debian, this is overridden by the CHECK_INTERVALS var in
10# /etc/default/monit . the below assumes you've set it to 30 seconds. 10# /etc/default/monit . the below assumes you've set it to 30 seconds.
11# 11#
12# if process dies, will restart sim within 30 seconds. if process
13# dies 5 times in as many tries, will stop trying and send email
14# alert.
15#
16# if SimFPS drops to 0 for 2 minutes, restart.
17#
18# if process CPU usage stays above 300% for 2 minutes, restart.
19#
20# see ../README for configuration instructions. 12# see ../README for configuration instructions.
21# 13#
22# Hmmmm, seems that monit changing to a user and running bash -l is different from sudo changing to a user and running bash -l. 14# Hmmmm, seems that monit changing to a user and running bash -l is different from sudo changing to a user and running bash -l.
23# 15#
24check process sim01 with pidfile /var/run/opensim/sim01.pid 16check process simSIM_NUMBER with pidfile /OS_PATH/caches/simSIM_NUMBER.pid
25 start program = "/usr/bin/sudo -Hu opensim /bin/bash -lc 'cd /opt/opensim/config/sim01 && /opt/opensim/config/sim01/start-sim -q'" 17 start program = "/usr/bin/sudo -Hu opensim /bin/bash -lc 'cd /OS_PATH/config/simSIM_NUMBER && /OS_PATH/config/simSIM_NUMBER/start-sim -q'"
26 as uid root and gid root 18 as uid root and gid root
27 stop program = "/usr/bin/sudo -Hu opensim /bin/bash -lc 'cd /opt/opensim/config/sim01 && /opt/opensim/config/sim01/stop-sim'" with timeout 600 seconds 19 stop program = "/usr/bin/sudo -Hu opensim /bin/bash -lc 'cd /OS_PATH/config/simSIM_NUMBER && /OS_PATH/config/simSIM_NUMBER/stop-sim'" with timeout 600 seconds
28 if cpu usage > 50% for 4 cycles then restart 20 if cpu usage > 50% for 4 cycles then restart
21 if MEMORY usage > 10% for 4 cycles then restart
29# if 5 restarts within 5 cycles then timeout 22# if 5 restarts within 5 cycles then timeout
30# if failed url http://127.0.0.1:9005/jsonSimStats/ 23# if failed url http://127.0.0.1:9005/jsonSimStats/
31# and content != '"SimFPS":0.0,' for 4 cycles 24# and content != '"SimFPS":0.0,' for 4 cycles
@@ -33,4 +26,4 @@ check process sim01 with pidfile /var/run/opensim/sim01.pid
33# if failed url http://127.0.0.1:9008/jsonSimStats/ 26# if failed url http://127.0.0.1:9008/jsonSimStats/
34# and content == '"SimFPS":' for 4 cycles 27# and content == '"SimFPS":' for 4 cycles
35# then restart 28# then restart
36 29 depends on ROBUST
diff --git a/scripts/install/secure.sh b/scripts/install/secure.sh
new file mode 100755
index 0000000..48255b6
--- /dev/null
+++ b/scripts/install/secure.sh
@@ -0,0 +1,20 @@
1#!/bin/bash
2
3source ../common.sh
4
5echo "Securing OpenSim."
6sudo chmod 600 ${OS_PATH}/config/*.ini
7sudo chown -R ${OS_USER}:${OS_USER} ${OS_PATH}
8sudo chmod -R 775 ${OS_PATH}
9sudo chmod -R a-x ${OS_PATH}
10sudo chmod -R a+X ${OS_PATH}
11sudo chmod -R g+w ${OS_PATH}
12sudo chmod -R a+x ${OS_PATH}/current/*.sh
13sudo chmod -R a+x ${OS_PATH}/current/scripts/*.sh
14sudo chmod -R a+x ${OS_PATH}/current/scripts/install/*.sh
15sudo chmod a+x ${OS_PATH}/current/scripts/show-console
16sudo chmod a+x ${OS_PATH}/current/scripts/start-sim
17
18sudo chmod ug+rwx ${OS_PATH}/config
19sudo chmod g+s ${OS_PATH}/config
20sudo chmod 600 ${OS_PATH}/config/*.ini
diff --git a/scripts/start-sim b/scripts/start-sim
index bd0815f..e82547a 100755
--- a/scripts/start-sim
+++ b/scripts/start-sim
@@ -38,11 +38,11 @@ fi
38if [ "x$1" = "x" ]; then 38if [ "x$1" = "x" ]; then
39 tgt=$(basename $(pwd)) 39 tgt=$(basename $(pwd))
40 num="$(echo ${tgt} | cut -c 4-)" 40 num="$(echo ${tgt} | cut -c 4-)"
41elif [ -d "./$1" ]; then 41elif [ -d "$1" ]; then
42 tgt=$1 42 tgt=$1
43elif [ -d "./sim$1" ]; then 43elif [ -d "sim$1" ]; then
44 num=$1 44 num=$1
45 tgt="./sim${num}" 45 tgt="sim${num}"
46else 46else
47 tgt=$1 47 tgt=$1
48 inventory=$1 48 inventory=$1
@@ -77,14 +77,14 @@ fi
77 77
78case $(basename $0) in 78case $(basename $0) in
79 "start-sim") 79 "start-sim")
80 cmd="mono ${exe}.exe -inidirectory=${tgt} " 80 cmd="mono ${exe}.exe -inidirectory=../../config/${tgt} "
81 81
82 # Check if it's already running. 82 # Check if it's already running.
83 if [ -e /var/run/opensim/${tgt}.pid ] 83 if [ -e /var/run/opensim/${tgt}.pid ]
84 then 84 then
85 # Double check if it's REALLY running. 85 # Double check if it's REALLY running.
86 if [ "x$(ps -p $(cat /var/run/opensim/${tgt}.pid) --no-headers -o comm)" = "x" ]; then 86 if [ "x$(ps -p $(cat ${PRGDIR}/../../caches/${tgt}.pid) --no-headers -o comm)" = "x" ]; then
87 $SUDO rm -f /var/run/opensim/${tgt}.pid 87 $SUDO rm -f ${PRGDIR}/../../caches/${tgt}.pid
88 fi 88 fi
89 fi 89 fi
90 # Now see if it's really really running. lol 90 # Now see if it's really really running. lol
@@ -92,9 +92,9 @@ case $(basename $0) in
92 then 92 then
93 if [ "x$tgt" = "xROBUST" ]; then 93 if [ "x$tgt" = "xROBUST" ]; then
94# TODO - the problem here is that the > bit is executed as onefang, not as opensim. 94# TODO - the problem here is that the > bit is executed as onefang, not as opensim.
95 $SUDO cat ../config/config.ini ../config/Robust.ini.template >../config/Robust.ini 95 $SUDO cat ${PRGDIR}/../../config/config.ini ${PRGDIR}/../../config/Robust.ini.template >${PRGDIR}/../../config/Robust.ini
96# $SUDO chown -R opensim:opensim ../config/Robust.ini 96# $SUDO chown -R opensim:opensim ${PRGDIR}/../../config/Robust.ini
97 chmod 640 ../config/Robust.ini 97 chmod 640 ${PRGDIR}/../../config/Robust.ini
98 ${tmux_command} split-window -hp 50 -t "${tmux_session}:" "${cmd}" 98 ${tmux_command} split-window -hp 50 -t "${tmux_session}:" "${cmd}"
99 else 99 else
100 ${tmux_command} new-window -dn "${title}" -t "${tmux_session}:${num}" "${cmd}" 100 ${tmux_command} new-window -dn "${title}" -t "${tmux_session}:${num}" "${cmd}"