aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/start-sim-screen
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xstart-sim-screen96
1 files changed, 96 insertions, 0 deletions
diff --git a/start-sim-screen b/start-sim-screen
new file mode 100755
index 0000000..12c8f8f
--- /dev/null
+++ b/start-sim-screen
@@ -0,0 +1,96 @@
1#!/bin/bash
2
3USER=$(whoami)
4console_name="OpenSim_console"
5screen_session=opensim/${console_name}
6screen_check="screen -ls opensim/"
7osversion="current"
8bindir=/opt/opensim/${osversion}/bin
9quiet=""
10
11if [ "$1" = "-q" ]
12then
13 quiet="true"
14 shift 1
15fi
16
17if [ "x$1" = "x" ]; then
18 pathname=$(pwd)
19 tgt=$(basename $pathname)
20elif [ -d "./$1" ]; then
21 tgt=$1
22elif [ -d "./sim$1" ]; then
23 tgt=sim$1
24fi
25
26if [ "x$tgt" = "x" ]; then
27 echo "usage:"
28 echo " $ $(basename $0) <sim>"
29 echo "where <sim> is one of: " robust sim[0-9][0-9]
30 exit 1
31fi
32
33if [ $USER = "opensim" ]
34then
35 SUDO=""
36else
37 SUDO="sudo -Hu opensim"
38fi
39
40# Would be nice if this worked.
41export MONO_PATH=${bindir}
42# Then we would not have to do this, and subsequently write all over the damn bin directory.
43cd ${bindir}
44
45if ($screen_check | grep -q ${console_name}); then
46 true
47else
48 $SUDO screen -d -m -S ${console_name}
49fi
50
51if [ "x$tgt" = "xrobust" ]; then
52 exe="Robust"
53else
54 exe="OpenSim"
55fi
56
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
69 "start-sim")
70 cmd="/usr/bin/mono ${bindir}/${exe}.exe -inidirectory=${inidir} -logconfig=${inidir}/${exe}.exe.config"
71
72 # Check if it's already running.
73 if [ ! -e /var/run/opensim/${tgt}.pid ]
74 then
75 $SUDO screen -r ${screen_session} -p "-" -X screen -t "[${title}]" ${cmd}
76 fi
77 ;&
78
79 "sim-console")
80 if [ "x$quiet" = "x" ]
81 then
82 screen -r ${screen_session} -p "[${title}]" -A
83 fi
84 ;;
85
86 "backup-sim")
87 # 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"
89 $SUDO screen -r opensim/OpenSim_console -p "[${title}]" -X stuff "${cmd}$(/bin/echo -ne '\015')"
90 ;;
91
92 "stop-sim")
93 $SUDO screen -r opensim/OpenSim_console -p "[${title}]" -X stuff "shutdown$(/bin/echo -ne '\015')"
94 ;;
95esac
96