aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/scripts
diff options
context:
space:
mode:
authoronefang2019-09-11 16:36:50 +1000
committeronefang2019-09-11 16:36:50 +1000
commit50cd1ffd32f69228e566f2b0b89f86ea0d9fe489 (patch)
tree52f2ab0c04f1a5d7d6ac5dc872981b4b156447e7 /scripts
parentRenamed branch to SledjChisl. (diff)
parentBump to release flavour, build 0. (diff)
downloadopensim-SC-50cd1ffd32f69228e566f2b0b89f86ea0d9fe489.zip
opensim-SC-50cd1ffd32f69228e566f2b0b89f86ea0d9fe489.tar.gz
opensim-SC-50cd1ffd32f69228e566f2b0b89f86ea0d9fe489.tar.bz2
opensim-SC-50cd1ffd32f69228e566f2b0b89f86ea0d9fe489.tar.xz
Merge branch 'SledjChisl'
Diffstat (limited to '')
-rw-r--r--example/config/ROBUST/opensim-monit.conf (renamed from scripts/opensim-monit.conf)6
-rwxr-xr-xscripts/backup-inventories.sh2
-rwxr-xr-xscripts/backup-sims.sh5
-rwxr-xr-xscripts/common.sh11
-rwxr-xr-xscripts/create_sim.sh96
-rwxr-xr-xscripts/fix_var_run.sh6
-rwxr-xr-xscripts/install/create_sim.sh75
-rwxr-xr-xscripts/install/go_live.sh (renamed from scripts/go_live.sh)2
-rw-r--r--scripts/install/group_migrate.sql (renamed from scripts/group_migrate.sql)0
-rw-r--r--scripts/install/opensim-monit.conf (renamed from config/ROBUST/opensim-monit.conf)17
-rw-r--r--scripts/install/opensim.tmux.conf97
-rwxr-xr-xscripts/install/secure.sh26
-rw-r--r--scripts/opensim.tmux.conf52
-rwxr-xr-xscripts/show-console2
-rwxr-xr-xscripts/start-sim109
15 files changed, 299 insertions, 207 deletions
diff --git a/scripts/opensim-monit.conf b/example/config/ROBUST/opensim-monit.conf
index 7785056..adce46d 100644
--- a/scripts/opensim-monit.conf
+++ b/example/config/ROBUST/opensim-monit.conf
@@ -21,10 +21,10 @@
21# 21#
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. 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.
23# 23#
24check process sim01 with pidfile /var/run/opensim/sim01.pid 24check process ROBUST with pidfile OS_PATH/caches/ROBUST.pid
25 start program = "/usr/bin/sudo -Hu opensim /bin/bash -lc 'cd /opt/opensim/config/sim01 && /opt/opensim/config/sim01/start-sim -q'" 25 start program = "/usr/bin/sudo -Hu opensim /bin/bash -lc 'cd OS_PATH/config/ROBUST && OS_PATH/config/ROBUST/start-sim -q'"
26 as uid root and gid root 26 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 27 stop program = "/usr/bin/sudo -Hu opensim /bin/bash -lc 'cd OS_PATH/config/ROBUST && OS_PATH/config/ROBUST/stop-sim'" with timeout 600 seconds
28 if cpu usage > 50% for 4 cycles then restart 28 if cpu usage > 50% for 4 cycles then restart
29# if 5 restarts within 5 cycles then timeout 29# if 5 restarts within 5 cycles then timeout
30# if failed url http://127.0.0.1:9005/jsonSimStats/ 30# if failed url http://127.0.0.1:9005/jsonSimStats/
diff --git a/scripts/backup-inventories.sh b/scripts/backup-inventories.sh
index db4d7f4..e4e7158 100755
--- a/scripts/backup-inventories.sh
+++ b/scripts/backup-inventories.sh
@@ -9,7 +9,7 @@ while read -d ';' p; do
9 k=$(echo ${p} | cut -d '=' -f 1) 9 k=$(echo ${p} | cut -d '=' -f 1)
10 v=$(echo ${p} | cut -d '=' -f 2) 10 v=$(echo ${p} | cut -d '=' -f 2)
11 creds[${k}]="${v}" 11 creds[${k}]="${v}"
12done < <(grep ConnectionString ${PRGDIR}/../config/config.ini | cut -d '"' -f 2) 12done < <(grep ConnectionString ${PRGDIR}/../../config/config.ini | cut -d '"' -f 2)
13# The above seems the best way to get bash to let the creds assignments survive outside the loop. 13# The above seems the best way to get bash to let the creds assignments survive outside the loop.
14 14
15# Only backup those that have not logged on since their last backup, but returning prims from sims will bypass this check. 15# Only backup those that have not logged on since their last backup, but returning prims from sims will bypass this check.
diff --git a/scripts/backup-sims.sh b/scripts/backup-sims.sh
index b14acca..06cb780 100755
--- a/scripts/backup-sims.sh
+++ b/scripts/backup-sims.sh
@@ -5,10 +5,9 @@ getPrgDir
5 5
6for i in $(seq -w 1 99) 6for i in $(seq -w 1 99)
7do 7do
8 j=$(num2name ${i}) 8 if [ -e "${PRGDIR}/../../config/sim${i}" ]
9 if [ -e "${PRGDIR}/../config/${j}" ]
10 then 9 then
11 pushd ${PRGDIR}/../config/${j} >/dev/null 10 pushd ${PRGDIR}/../../config/sim${i} >/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. 11 # 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})"` 12 sizeSleep=`sleepPerSize o "$(getSimName ${i})"`
14 ./backup-sim 13 ./backup-sim
diff --git a/scripts/common.sh b/scripts/common.sh
index 2ec19ce..6aeb8b5 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)
@@ -26,9 +28,7 @@ getPrgDir()
26# name=$(num2name 1) 28# name=$(num2name 1)
27num2name() 29num2name()
28{ 30{
29 # Using a string format, coz using a number format ends with an octal error, coz 08 isn't a valid octal number. 31 /usr/bin/printf 'sim%02d' "$1"
30 # Why isn't octal dead already?
31 printf 'sim%02s' "$1"
32} 32}
33 33
34 34
@@ -40,11 +40,11 @@ sanitize()
40} 40}
41 41
42 42
43# Grab the first Section line of the sims .xml file, cut it down to the name. 43# Grab the first Section line of the sims .ini file, cut it down to the name.
44# name=$(getSimName 1) 44# name=$(getSimName 1)
45getSimName() 45getSimName()
46{ 46{
47 grep "<Section " ${PRGDIR}/../../config/$(num2name $1)/*.xml | head -n 1 | cut -d '"' -f 2 47 grep "RegionName" ${PRGDIR}/../../config/sim$1/*.ini | head -n 1 | cut -d '"' -f 2
48} 48}
49 49
50 50
@@ -73,4 +73,3 @@ sleepPerSize()
73 echo 200 73 echo 200
74 fi 74 fi
75} 75}
76
diff --git a/scripts/create_sim.sh b/scripts/create_sim.sh
deleted file mode 100755
index 0681067..0000000
--- a/scripts/create_sim.sh
+++ /dev/null
@@ -1,96 +0,0 @@
1#!/bin/bash
2
3source common.sh
4getPrgDir
5
6NAME=$1
7LOCATION=$2
8URL=$3
9IP=$4
10SIZE=$5
11
12OSPATH="/opt/opensim"
13cd $OSPATH/config
14
15k=0
16for i in $(seq -w 1 99)
17do
18 j=$(num2name "$i")
19 if [ -e "$j" ]
20 then
21 k=$i
22 fi
23done
24
25if [ "x$NAME" = "x" ]
26then
27 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."
29fi
30# Sanitize the name. Not removing [ or ], couldn't get that to work, only important for Windows.
31sim=$(sanitize $NAME)
32
33if [ "x$LOCATION" = "x" ]
34then
35 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."
37fi
38
39if [ "x$IP" = "x" ]
40then
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"
43 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."
45# According to the OpenSim docs, 0.0.0.0 means to listen on all NICs the machine has, which should work fine.
46fi
47
48if [ "x$URL" = "x" ]
49then
50# 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.
52 URL="SYSTEMIP"
53 echo "WARNING setting the ExternalHostName to $URL, this may not be what you want."
54fi
55
56if [ "x$SIZE" = "x" ]
57then
58 SIZE="256"
59fi
60
61# Wow, the hoops we have to jump through to avoid octal.
62if [ 9 -gt $k ]; then
63 NUM=$(printf '0%1s' $(( 10#$k + 1 )) )
64else
65 NUM=$(printf '%2s' $(( 10#$k + 1 )) )
66fi
67
68PORT=$(( 9005 + (10#$k * 5) )) # 9002 is used for HTTP/UDP so START with port 9003! CAUTION Diva/D2 starts at port 9000.
69UUID=$(uuidgen)
70
71echo "Creating sim$NUM on port $PORT @ $LOCATION - $NAME."
72
73cp -r sim_skeleton sim$NUM
74
75cd sim$NUM
76mv My_sim.xml ${sim}.xml
77sed -i "s@SIM_NAME@$NAME@g" ${sim}.xml
78sed -i "s@SIM_UUID@$UUID@g" ${sim}.xml
79sed -i "s@SIM_POS@$LOCATION@g" ${sim}.xml
80sed -i "s@SIM_IP@$IP@g" ${sim}.xml
81sed -i "s@SIM_INT_PORT@$(( $PORT + 1 ))@g" ${sim}.xml
82sed -i "s@SIM_URL@$URL@g" ${sim}.xml
83sed -i "s@SIM_SIZE@$SIZE@g" ${sim}.xml
84
85ln -s ../../current/scripts/common.sh common.sh
86ln -s ../../current/scripts/start-sim start-sim
87cp -P start-sim backup-sim
88cp -P start-sim stop-sim
89
90sed -i "s@SIM_NUMBER@$NUM@g" ThisSim.ini
91sed -i "s@SIM_PORT@$PORT@g" ThisSim.ini
92
93sed -i "s@SIM_NUMBER@$NUM@g" opensim-monit.conf
94
95sudo chown -R opensim:opensim ..
96sudo chmod -R g+w ..
diff --git a/scripts/fix_var_run.sh b/scripts/fix_var_run.sh
deleted file mode 100755
index 97567cb..0000000
--- a/scripts/fix_var_run.sh
+++ /dev/null
@@ -1,6 +0,0 @@
1# Create the opensim run dir.
2mkdir -p /var/run/opensim
3chown opensim:opensim /var/run/opensim
4chmod ug+rwx /var/run/opensim
5chmod o-rwx /var/run/opensim
6chmod g+s /var/run/opensim
diff --git a/scripts/install/create_sim.sh b/scripts/install/create_sim.sh
new file mode 100755
index 0000000..b940315
--- /dev/null
+++ b/scripts/install/create_sim.sh
@@ -0,0 +1,75 @@
1#!/bin/bash
2
3source ../common.sh
4getPrgDir
5
6NAME=$1
7LOCATION=$2
8SIZE=$3
9
10cd ${OS_PATH}/config
11
12k=0
13for i in $(seq -w 1 99)
14do
15 if [ -e "sim$i" ]
16 then
17 k=$i
18 fi
19done
20
21if [ "x${NAME}" = "x" ]
22then
23 NAME="No name sim $RANDOM" # Should be unique per grid.
24 echo "WARNING setting the sim name to [${NAME}], this may not be what you want."
25fi
26# Sanitize the name. Not removing [ or ], couldn't get that to work, only important for Windows.
27sim=$(sanitize ${NAME})
28
29if [ "x${LOCATION}" = "x" ]
30then
31 LOCATION="$RANDOM,$RANDOM" # again UNIQUE (i.e. ONLY ONE) per grid in THIS case!
32 echo "WARNING setting the Location to ${LOCATION}, this may not be what you want."
33fi
34
35if [ "x${SIZE}" = "x" ]
36then
37 SIZE="256"
38fi
39
40# Wow, the hoops we have to jump through to avoid octal.
41if [ 9 -gt $k ]; then
42 NUM=$(printf '0%1s' $(( 10#$k + 1 )) )
43else
44 NUM=$(printf '%2s' $(( 10#$k + 1 )) )
45fi
46
47PORT=$(( 9005 + (10#$k * 2) )) # 9002 is used for HTTP/UDP so START with port 9003! CAUTION Diva/D2 starts at port 9000.
48UUID=$(uuidgen)
49
50echo "Creating sim${NUM} on port ${PORT} @ ${LOCATION} - ${NAME}."
51
52cp -r sim_skeleton sim${NUM}
53
54cd sim${NUM}
55sed -i "s@SIM_NAME@${NAME}@g" ThisSim.ini
56sed -i "s@SIM_UUID@${UUID}@g" ThisSim.ini
57sed -i "s@SIM_POS@${LOCATION}@g" ThisSim.ini
58sed -i "s@SIM_INT_PORT@$(( ${PORT} + 1 ))@g" ThisSim.ini
59sed -i "s@SIM_SIZE@${SIZE}@g" ThisSim.ini
60
61ln -s ../../current/scripts/common.sh common.sh
62ln -s ../../current/scripts/start-sim start-sim
63cp -P start-sim backup-sim
64cp -P start-sim stop-sim
65
66sed -i "s@SIM_NUMBER@${NUM}@g" ThisSim.ini
67sed -i "s@SIM_PORT@${PORT}@g" ThisSim.ini
68
69sed -i "s@OS_PATH@${OS_PATH}@g" opensim-monit.conf
70sed -i "s@SIM_NUMBER@${NUM}@g" opensim-monit.conf
71
72mv ThisSim.ini $(sanitize "${NAME}").ini
73
74sudo chown -R ${OS_USER}:${OS_USER} ..
75sudo chmod -R g+w ..
diff --git a/scripts/go_live.sh b/scripts/install/go_live.sh
index 21d7072..c5ce90e 100755
--- a/scripts/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/group_migrate.sql b/scripts/install/group_migrate.sql
index 6c15011..6c15011 100644
--- a/scripts/group_migrate.sql
+++ b/scripts/install/group_migrate.sql
diff --git a/config/ROBUST/opensim-monit.conf b/scripts/install/opensim-monit.conf
index 70190b9..409b69e 100644
--- a/config/ROBUST/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 ROBUST with pidfile /var/run/opensim/ROBUST.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/ROBUST && /opt/opensim/config/ROBUST/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/ROBUST && /opt/opensim/config/ROBUST/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 ROBUST with pidfile /var/run/opensim/ROBUST.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/opensim.tmux.conf b/scripts/install/opensim.tmux.conf
new file mode 100644
index 0000000..84e0c21
--- /dev/null
+++ b/scripts/install/opensim.tmux.conf
@@ -0,0 +1,97 @@
1# Tmux has a habit of changing what these options are for each version, so this is a bit of a mess.
2
3# Screen compatibility, change the command key. And rebind the prefix sending command.
4set-option -g prefix C-a
5unbind-key C-b
6bind-key C-a send-prefix
7
8# r reloads the configuration, handy
9bind r source-file ~/.tmux.conf
10
11bind R clear-history
12
13# More sane pane gain. B-)
14unbind % # Remove default binding since we’re replacing them.
15unbind '"'
16bind | split-window -h
17bind - split-window -v
18
19# set-options -g global, -s server, -w window, otherwise a session option.
20# -a appends a string to the existing option.
21# -u unsets an option.
22# -o prevents setting an aption if it is already set.
23# -q shut up info messages.
24
25# SESSION OPTIONS
26
27set-option -g bell-action any
28set-option -g bell-on-alert on
29
30# Not actually documented what the limit is, but there is one.
31set-option -g history-limit 100000
32
33# All this mouse stuff is unreliable in UTF8 mode. At least on roxterm.
34# Also keep in mind the terminal specs mouse report limit of 256 characters, being less than my typical terminal width.
35# Hmm, still wont pass mouse through like the docs say they will.
36# Ah, mc needs "mc -x". Though once again, watch that right edge on huge terminals.
37# These three wont work under Ubuntu 16.04.
38##set-option -g mouse-resize-pane on
39##set-option -g mouse-select-pane on
40##set-option -g mouse-select-window on
41# This wont work under Ubuntu 16.04.
42##set-option -g mode-mouse on # on - mouse does copy mode stuff; copy-mode - mouse can't go into copy mode, but does stuff once in there; off - mouse is unmolested.
43# Instead do this (also defaults to turning on the above three mouse things) -
44set-option -g mouse on
45# Or this. sigh
46#set-option -g mouse
47##set-option -g mouse-utf8 off # Defaults to on.
48
49set-option -g set-remain-on-exit on
50
51# How to set the title of the terminal window.
52set-option -g set-titles on
53set-option -g set-titles-string '#W' # Default is "#S:#I:#W - "#T""
54
55set-option -g status-interval 1 # Redraw status line every second, for the clock.
56set-option -g status-justify centre # Window list in the middle.
57##set-option -g status-utf8 on
58
59# Character pair Replaced with
60 #(shell-command) First line of the command's output
61 #[attributes] Colour or attribute change
62 #H Hostname of local host (not FDQN)
63 #h Hostname of local host without the domain name
64 #F Current window flag
65 #I Current window index
66 #D Current pane unique identifier
67 #P Current pane index
68 #S Session name
69 #T Current pane title
70 #W Current window name
71 ## A literal ‘#’
72
73# Yes, my terminal really is bigger than 160 characters.
74set-option -g status-left-length 42
75#set-option -g status-left '[#H #S #F]'
76set-option -g status-left '#H [#S:#I.#P]#F'
77set-option -g status-right-length 64
78set-option -g status-right "%F #(uptime | cut -d ' ' -f 2-2,10-)" # %F is ISO date, uptime starts with the current time, and ends with the load average. B-)
79
80# Set window notifications
81set-option -g visual-activity on # Show status message for activity in monitor-activity windows.
82#set-option -g visual-content on # Show status message for content in monitor-content windows. Based on a fnmatch(3) string.
83set-option -g visual-silence on # Show status message for silence in monitor-silence windows. Based on a set interval.
84
85set-option -gw alternate-screen off # Don't save the original screen before starting tmux, may also allow use of the terminals original scrollback buffer.
86set-option -gw clock-mode-style 24 # We are using the uptime clock anyway, so this is pointless.
87
88# Highlight active window
89set-option -gw window-status-current-bg red
90set-option -gw window-status-current-format '[#I:#W]'
91set-option -gw window-status-format '[#I:#W]#F'
92
93# Set window notifications
94set-option -gw monitor-activity on # Bell on activity.
95
96# We want 256 colours in our terminal.
97set-option -g default-terminal "screen-256color"
diff --git a/scripts/install/secure.sh b/scripts/install/secure.sh
new file mode 100755
index 0000000..95aae84
--- /dev/null
+++ b/scripts/install/secure.sh
@@ -0,0 +1,26 @@
1#!/bin/bash
2
3source ../common.sh
4
5echo "Securing OpenSim."
6sudo chmod 600 ${OS_PATH}/config/*.ini
7sudo chmod 600 ${OS_PATH}/config/ROBUST/*.ini
8sudo chown -R ${OS_USER}:${OS_USER} ${OS_PATH}
9sudo chmod -R 775 ${OS_PATH}
10sudo chmod -R a-x ${OS_PATH}
11sudo chmod -R a+X ${OS_PATH}
12sudo chmod -R g+w ${OS_PATH}
13sudo chmod -R a+x ${OS_PATH}/current/*.sh
14sudo chmod -R a+x ${OS_PATH}/current/scripts/*.sh
15sudo chmod -R a+x ${OS_PATH}/current/scripts/install/*.sh
16sudo chmod a+x ${OS_PATH}/current/scripts/show-console
17sudo chmod a+x ${OS_PATH}/current/scripts/start-sim
18
19sudo chmod ug+rwx ${OS_PATH}/config
20sudo chmod g+s ${OS_PATH}/config
21sudo chmod 600 ${OS_PATH}/config/*.ini
22sudo chmod 600 ${OS_PATH}/config/ROBUST/*.ini
23
24chmod ug+rwx ${OS_PATH}/caches
25chmod o-rwx ${OS_PATH}/caches
26chmod g+s ${OS_PATH}/caches
diff --git a/scripts/opensim.tmux.conf b/scripts/opensim.tmux.conf
deleted file mode 100644
index ea342a2..0000000
--- a/scripts/opensim.tmux.conf
+++ /dev/null
@@ -1,52 +0,0 @@
1# Tmux has a habit of changing what these options are for each version, so this is a bit of a mess.
2
3set-option -g prefix C-a
4unbind-key C-b
5bind-key C-a send-prefix
6
7# r reloads the configuration, handy
8bind r source-file ~/.tmux.conf
9
10unbind % # Remove default binding since we’re replacing them.
11bind | split-window -h
12bind - split-window -v
13
14set-option -g bell-action any
15set-option -g bell-on-alert on
16
17set-option -g history-limit 100000
18
19# These three wont work under Ubuntu 16.04.
20set-option -g mouse-resize-pane on
21set-option -g mouse-select-pane on
22set-option -g mouse-select-window on
23set-option -g mouse-utf8 on
24
25#set-option -g set-remain-on-exit on
26set-option -g set-titles on
27set-option -g set-titles-string '#W'
28
29set-option -g status-interval 1
30set-option -g status-justify centre
31set-option -g status-utf8 on
32
33set-option -g status-left-length 80
34set-option -g status-left '[#H #S #F]'
35set-option -g status-right-length 80
36set-option -g status-right '%F #(uptime)'<-----># &F is ISO date, uptime starts with the current time, and ends with the load average. B-)
37
38set-option -g visual-activity on
39set-option -g visual-content on
40set-option -g visual-silence on
41
42set-option -gw clock-mode-style 24
43# This wont work under Ubuntu 16.04.
44set-option -gw mode-mouse on
45# Instead do this (also defaults to turning on the above three mouse things) -
46#set-option -gw mouse on
47
48# Highlight active window
49set-option -gw window-status-current-bg red
50
51# Set window notifications
52set-option -gw monitor-activity on
diff --git a/scripts/show-console b/scripts/show-console
index ddeba86..e7fb941 100755
--- a/scripts/show-console
+++ b/scripts/show-console
@@ -1,3 +1,3 @@
1#!/bin/bash 1#!/bin/bash
2 2
3tmux -S /var/run/opensim/opensim-tmux.socket select-window -t "OpenSim_console" \; attach-session -t "OpenSim_console" 3tmux -S ../../caches/opensim-tmux.socket select-window -t "OpenSimSC" \; attach-session -t "OpenSimSC"
diff --git a/scripts/start-sim b/scripts/start-sim
index bd0815f..48c530a 100755
--- a/scripts/start-sim
+++ b/scripts/start-sim
@@ -4,14 +4,17 @@ source common.sh
4getPrgDir 4getPrgDir
5 5
6USER=$(whoami) 6USER=$(whoami)
7console_name="OpenSim_console" 7console_name="OpenSimSC"
8tmux_command="tmux -S /var/run/opensim/opensim-tmux.socket" 8tmux_command="tmux -S ${PRGDIR}/../../caches/opensim-tmux.socket"
9tmux_session=${console_name} 9tmux_session=${console_name}
10tmux_window="${tmux_command} select-window -t ${tmux_session}" 10tmux_window="${tmux_command} select-window -t ${tmux_session}"
11tmux_send="${tmux_command} send-keys -t ${tmux_session}" 11tmux_send="${tmux_command} send-keys -t ${tmux_session}"
12bindir="${PRGDIR}/../bin" 12bindir="${PRGDIR}/../bin"
13date=$(date '+%F_%T') 13date=$(date '+%F_%T')
14all=""
15delay=45
14quiet="" 16quiet=""
17waiting=""
15inventory="" 18inventory=""
16 19
17function wait_for_text() 20function wait_for_text()
@@ -22,27 +25,77 @@ function wait_for_text()
22 done 25 done
23} 26}
24 27
25if [ $USER = "opensim" ] 28
29if [ $USER = "${OS_USER}" ]
26then 30then
27 SUDO="" 31 SUDO=""
28else 32else
29 SUDO="sudo -Hu opensim" 33 SUDO="sudo -Hu ${OS_USER}"
34fi
35
36if [ "$1" = "-a" ]
37then
38 all="-a"
39 shift 1
40fi
41
42if [ "$1" = "-d" ]
43then
44 delay=$2
45 shift 2
30fi 46fi
31 47
32if [ "$1" = "-q" ] 48if [ "$1" = "-q" ]
33then 49then
34 quiet="true" 50 quiet="-q"
51 shift 1
52fi
53
54if [ "$1" = "-w" ]
55then
56 waiting="-w"
35 shift 1 57 shift 1
36fi 58fi
37 59
38if [ "x$1" = "x" ]; then 60if [ "x$1" = "x" ]; then
39 tgt=$(basename $(pwd)) 61 tgt=$(basename $(pwd))
62 # These checks are kludgy.
63 if [ "$tgt" = "scripts" ]; then
64 all="-a"
65 cd ${PRGDIR}/../../config/ROBUST
66 tgt="ROBUST"
67 fi
68 if [ "$tgt" = "bin" ]; then
69 uptime
70 wait_for_text "ROBUST" "INITIALIZATION COMPLETE FOR ROBUST"
71 if [ ! "x$all" = "x" ]
72 then
73 echo "Sleeping for $((${delay} / 2)) seconds."
74 sleep $((${delay} / 2))
75 for i in $(seq -w 1 99)
76 do
77 if [ -e "${PRGDIR}/../../config/sim${i}" ]
78 then
79 uptime
80 echo "Starting sim${i}."
81 cd ${PRGDIR}/../../config/sim${i}; ./start-sim -w
82 uptime
83 # Sleep for a while, so that there is plenty of time to finish starting scripts and such,
84 # and we are not keeping the computer very busy if there are lots of sims.
85 echo "Sleeping for ${delay} seconds."
86 sleep ${delay}
87 fi
88 done
89 uptime
90 fi
91 exit 0
92 fi
40 num="$(echo ${tgt} | cut -c 4-)" 93 num="$(echo ${tgt} | cut -c 4-)"
41elif [ -d "./$1" ]; then 94elif [ -d "$1" ]; then
42 tgt=$1 95 tgt=$1
43elif [ -d "./sim$1" ]; then 96elif [ -d "sim$1" ]; then
44 num=$1 97 num=$1
45 tgt="./sim${num}" 98 tgt="sim${num}"
46else 99else
47 tgt=$1 100 tgt=$1
48 inventory=$1 101 inventory=$1
@@ -61,8 +114,8 @@ if ( ${tmux_command} -q list-sessions 2>/dev/null | grep -q ${console_name}: );
61 true 114 true
62else 115else
63 # The sudo is only so that the session is owned by opensim, otherwise it's owned by whoever ran this script, which is a likely security hole. 116 # The sudo is only so that the session is owned by opensim, otherwise it's owned by whoever ran this script, which is a likely security hole.
64 # After the session is created, we rely on the /var/run/opensim directory to be group sticky, so that anyone in the opensim group can attach to the tmux socket. 117 # After the session is created, we rely on the ${PRGDIR}/../../caches/ directory to be group sticky, so that anyone in the opensim group can attach to the tmux socket.
65 $SUDO ${tmux_command} new-session -d -s ${console_name} -n "Server" 118 $SUDO ${tmux_command} new-session -d -s ${console_name} -n "ROBUST"
66fi 119fi
67 120
68 121
@@ -71,36 +124,37 @@ if [ "x$tgt" = "xROBUST" ]; then
71 title="ROBUST" 124 title="ROBUST"
72elif [ "x$inventory" = "x" ]; then 125elif [ "x$inventory" = "x" ]; then
73 exe="OpenSim" 126 exe="OpenSim"
74 # Grab the first Section line of the sims .xml file, cut it down to the name. 127 # Grab the first RegionName line of the sims .ini file, cut it down to the name.
75 title=$(getSimName ${num}) 128 title=$(getSimName ${num})
76fi 129fi
77 130
78case $(basename $0) in 131case $(basename $0) in
79 "start-sim") 132 "start-sim")
80 cmd="mono ${exe}.exe -inidirectory=${tgt} " 133 cmd="mono ${exe}.exe -inidirectory=../../config/${tgt} "
81 134
82 # Check if it's already running. 135 # Check if it's already running.
83 if [ -e /var/run/opensim/${tgt}.pid ] 136 if [ -e ${PRGDIR}/../../caches/${tgt}.pid ]
84 then 137 then
85 # Double check if it's REALLY running. 138 # Double check if it's REALLY running.
86 if [ "x$(ps -p $(cat /var/run/opensim/${tgt}.pid) --no-headers -o comm)" = "x" ]; then 139 if [ "x$(ps -p $(cat ${PRGDIR}/../../caches/${tgt}.pid) --no-headers -o comm)" = "x" ]; then
87 $SUDO rm -f /var/run/opensim/${tgt}.pid 140 $SUDO rm -f ${PRGDIR}/../../caches/${tgt}.pid
88 fi 141 fi
89 fi 142 fi
90 # Now see if it's really really running. lol 143 # Now see if it's really really running. lol
91 if [ ! -e /var/run/opensim/${tgt}.pid ] 144 if [ ! -e ${PRGDIR}/../../caches/${tgt}.pid ]
92 then 145 then
93 if [ "x$tgt" = "xROBUST" ]; then 146 if [ "x$tgt" = "xROBUST" ]; then
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
96# $SUDO chown -R opensim:opensim ../config/Robust.ini
97 chmod 640 ../config/Robust.ini
98 ${tmux_command} split-window -hp 50 -t "${tmux_session}:" "${cmd}" 147 ${tmux_command} split-window -hp 50 -t "${tmux_session}:" "${cmd}"
99 else 148 else
100 ${tmux_command} new-window -dn "${title}" -t "${tmux_session}:${num}" "${cmd}" 149 ${tmux_command} new-window -dn "${title}" -t "${tmux_session}:${num}" "${cmd}"
101 fi 150 fi
102 fi 151 fi
103 152
153 if [ ! "x$all" = "x" ]
154 then
155 ${tmux_send}:ROBUST.{left} "../scripts/start-sim -a -d ${delay}" Enter
156 fi
157
104 if [ "x$quiet" = "x" ] 158 if [ "x$quiet" = "x" ]
105 then 159 then
106 if [ "x$tgt" = "xROBUST" ]; then 160 if [ "x$tgt" = "xROBUST" ]; then
@@ -108,7 +162,10 @@ case $(basename $0) in
108 fi 162 fi
109 fi 163 fi
110 164
111 ${tmux_send}:"${title}" Enter Enter Enter 165 if [ ! "x$waiting" = "x" ]
166 then
167 wait_for_text "${title}" "INITIALIZATION COMPLETE FOR ${title}"
168 fi
112 ;; 169 ;;
113 170
114 "backup-inventory") 171 "backup-inventory")
@@ -124,7 +181,7 @@ case $(basename $0) in
124 ;; 181 ;;
125 182
126 "backup-sim") 183 "backup-sim")
127 if [ -e /var/run/opensim/${tgt}.pid ]; then 184 if [ -e ${PRGDIR}/../../caches/${tgt}.pid ]; then
128 cd ${PRGDIR} 185 cd ${PRGDIR}
129 $SUDO ${PRGDIR}/gitAR.sh o "${title}" 186 $SUDO ${PRGDIR}/gitAR.sh o "${title}"
130 sim=$(sanitize "${title}") 187 sim=$(sanitize "${title}")
@@ -141,7 +198,7 @@ case $(basename $0) in
141 ;; 198 ;;
142 199
143 "stop-sim") 200 "stop-sim")
144 if [ -e /var/run/opensim/${tgt}.pid ]; then 201 if [ -e ${PRGDIR}/../../caches/${tgt}.pid ]; then
145 ${tmux_send}:"${title}" "alert WARNING - Emergency shutdown in one minute!" Enter 202 ${tmux_send}:"${title}" "alert WARNING - Emergency shutdown in one minute!" Enter
146 ${tmux_send}:"${title}" "alert WARNING - Emergency shutdown in one minute!" Enter 203 ${tmux_send}:"${title}" "alert WARNING - Emergency shutdown in one minute!" Enter
147 sleep 30 204 sleep 30
@@ -150,9 +207,9 @@ case $(basename $0) in
150 sleep 30 207 sleep 30
151 ${tmux_send}:"${title}" "shutdown" Enter 208 ${tmux_send}:"${title}" "shutdown" Enter
152 sleep 30 209 sleep 30
153 if [ -e /var/run/opensim/${tgt}.pid ]; then 210 if [ -e ${PRGDIR}/../../caches/${tgt}.pid ]; then
154 echo "Killing it with extreme prejudice!" 211 echo "Killing it with extreme prejudice!"
155 kill -TERM `cat /var/run/opensim/${tgt}.pid` 212 kill -TERM `cat ${PRGDIR}/../../caches/${tgt}.pid`
156 fi 213 fi
157 else 214 else
158 echo "Sim ${title} is not running, so not stopping." 215 echo "Sim ${title} is not running, so not stopping."