aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/scripts/start-sim
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/start-sim')
-rwxr-xr-xscripts/start-sim109
1 files changed, 83 insertions, 26 deletions
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."