aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/start-sim
diff options
context:
space:
mode:
Diffstat (limited to 'start-sim')
-rwxr-xr-xstart-sim58
1 files changed, 31 insertions, 27 deletions
diff --git a/start-sim b/start-sim
index 12c8f8f..df66790 100755
--- a/start-sim
+++ b/start-sim
@@ -2,8 +2,9 @@
2 2
3USER=$(whoami) 3USER=$(whoami)
4console_name="OpenSim_console" 4console_name="OpenSim_console"
5screen_session=opensim/${console_name} 5screen_command="tmux -S /var/run/opensim/opensim-tmux.socket"
6screen_check="screen -ls opensim/" 6screen_session=${console_name}
7screen_window="${screen_command} select-window -t ${screen_session}"
7osversion="current" 8osversion="current"
8bindir=/opt/opensim/${osversion}/bin 9bindir=/opt/opensim/${osversion}/bin
9quiet="" 10quiet=""
@@ -30,67 +31,70 @@ if [ "x$tgt" = "x" ]; then
30 exit 1 31 exit 1
31fi 32fi
32 33
33if [ $USER = "opensim" ]
34then
35 SUDO=""
36else
37 SUDO="sudo -Hu opensim"
38fi
39
40# Would be nice if this worked. 34# Would be nice if this worked.
41export MONO_PATH=${bindir} 35export MONO_PATH=${bindir}
42# Then we would not have to do this, and subsequently write all over the damn bin directory. 36# Then we would not have to do this, and subsequently write all over the damn bin directory.
43cd ${bindir} 37cd ${bindir}
44 38
45if ($screen_check | grep -q ${console_name}); then 39if ( ${screen_command} -q list-sessions 2>/dev/null | grep -q ${console_name}: ); then
46 true 40 true
47else 41else
48 $SUDO screen -d -m -S ${console_name} 42 if [ $USER = "opensim" ]
43 then
44 SUDO=""
45 else
46 SUDO="sudo -Hu opensim"
47 fi
48 # The sudo is only so that the session is owned by opensim, otherwise it's owned by whoewer ran this script, which is a likely security hole.
49 # 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.
50 $SUDO ${screen_command} new-session -d -s ${console_name}
49fi 51fi
50 52
53inidir=/opt/opensim/config/${tgt}
54
51if [ "x$tgt" = "xrobust" ]; then 55if [ "x$tgt" = "xrobust" ]; then
52 exe="Robust" 56 exe="Robust"
57 title="ROBUST"
58 roboini="-inifile=${inidir}/Robust.ini"
53else 59else
54 exe="OpenSim" 60 exe="OpenSim"
61 # Grab the first line of the sim.ini file, it should be the sim name in square brackets.
62 title=$(head -n 1 ${inidir}/Regions/sim.ini )
63 # Strip off spaces at either end.
64 shopt -s extglob
65 title=${title##*( )}
66 title=${title%%*( )}
67 shopt -u extglob
68 # Strip off the square brackets at either end.
69 title=${title:1:$(( ${#title} - 2 ))}
55fi 70fi
56 71
57inidir=/opt/opensim/config/${tgt}
58# Grab the first line of the sim.ini file, it should be the sim name in square brackets.
59title=$(head -n 1 ${inidir}/Regions/sim.ini )
60# Strip off spaces at either end.
61shopt -s extglob
62title=${title##*( )}
63title=${title%%*( )}
64shopt -u extglob
65# Strip off the square brackets at either end.
66title=${title:1:$(( ${#title} - 2 ))}
67
68case $(basename $0) in 72case $(basename $0) in
69 "start-sim") 73 "start-sim")
70 cmd="/usr/bin/mono ${bindir}/${exe}.exe -inidirectory=${inidir} -logconfig=${inidir}/${exe}.exe.config" 74 cmd="/usr/bin/mono ${bindir}/${exe}.exe -inidirectory=${inidir} -logconfig=${inidir}/${exe}.exe.config ${roboini}"
71 75
72 # Check if it's already running. 76 # Check if it's already running.
73 if [ ! -e /var/run/opensim/${tgt}.pid ] 77 if [ ! -e /var/run/opensim/${tgt}.pid ]
74 then 78 then
75 $SUDO screen -r ${screen_session} -p "-" -X screen -t "[${title}]" ${cmd} 79 ${screen_command} new-window -dn "[${title}]" -t "${screen_session}" "${cmd}"
76 fi 80 fi
77 ;& 81 ;&
78 82
79 "sim-console") 83 "sim-console")
80 if [ "x$quiet" = "x" ] 84 if [ "x$quiet" = "x" ]
81 then 85 then
82 screen -r ${screen_session} -p "[${title}]" -A 86 ${screen_window}:"[${title}]" \; attach-session -t "${screen_session}"
83 fi 87 fi
84 ;; 88 ;;
85 89
86 "backup-sim") 90 "backup-sim")
87 # Substitute underscores for spaces in the title, then add the full date and time to create the OAR file name. 91 # Substitute underscores for spaces in the title, then add the full date and time to create the OAR file name.
88 cmd="save oar ${inidir}/../../backups/${title// /_}-$(date '+%F_%T').oar" 92 cmd="save oar ${inidir}/../../backups/${title// /_}-$(date '+%F_%T').oar"
89 $SUDO screen -r opensim/OpenSim_console -p "[${title}]" -X stuff "${cmd}$(/bin/echo -ne '\015')" 93 ${screen_window}:"[${title}]" \; send-keys "${cmd}" Enter
90 ;; 94 ;;
91 95
92 "stop-sim") 96 "stop-sim")
93 $SUDO screen -r opensim/OpenSim_console -p "[${title}]" -X stuff "shutdown$(/bin/echo -ne '\015')" 97 ${screen_window}:"[${title}]" \; send-keys "shutdown" Enter
94 ;; 98 ;;
95esac 99esac
96 100