diff options
Diffstat (limited to '')
-rwxr-xr-x | install_opensim.sh | 9 | ||||
-rw-r--r-- | opensim.tmux.conf | 47 | ||||
-rwxr-xr-x | start-sim | 58 | ||||
-rwxr-xr-x | start-sim-screen | 96 |
4 files changed, 180 insertions, 30 deletions
diff --git a/install_opensim.sh b/install_opensim.sh index 2ef71c2..1967e36 100755 --- a/install_opensim.sh +++ b/install_opensim.sh | |||
@@ -13,7 +13,7 @@ OSPATH="/opt/opensim" | |||
13 | USER=$(whoami) | 13 | USER=$(whoami) |
14 | VERSION_CONTROL="off" | 14 | VERSION_CONTROL="off" |
15 | 15 | ||
16 | sudo apt-get install mysql-server screen mono-complete monit mc | 16 | sudo apt-get install mysql-server tmux screen mono-complete monit mc |
17 | sudo /etc/init.d/mysql restart | 17 | sudo /etc/init.d/mysql restart |
18 | 18 | ||
19 | echo "Setting up mySQL" | 19 | echo "Setting up mySQL" |
@@ -34,12 +34,15 @@ sudo chown $USER /home/opensim/.screenrc | |||
34 | echo -e "acladd root,$USER\n" >> /home/opensim/.screenrc | 34 | echo -e "acladd root,$USER\n" >> /home/opensim/.screenrc |
35 | sudo chown opensim:opensim /home/opensim/.screenrc | 35 | sudo chown opensim:opensim /home/opensim/.screenrc |
36 | sudo chmod 644 /home/opensim/.screenrc | 36 | sudo chmod 644 /home/opensim/.screenrc |
37 | sudo cp opensim.tmux.conf /home/opensim/.tmux.conf | ||
38 | sudo chown $USER /home/opensim/.tmux.conf | ||
39 | sudo chmod 644 /home/opensim/.tmux.conf | ||
37 | sudo mkdir -p /var/log/opensim | 40 | sudo mkdir -p /var/log/opensim |
38 | sudo chown opensim:opensim /var/log/opensim | 41 | sudo chown opensim:opensim /var/log/opensim |
39 | sudo chmod 757 /var/log/opensim | 42 | sudo chmod 757 /var/log/opensim |
40 | sudo mkdir -p /var/run/opensim | 43 | sudo mkdir -p /var/run/opensim |
41 | sudo chown opensim:opensim /var/run/opensim | 44 | sudo chown opensim:opensim /var/run/opensim |
42 | sudo chmod 757 /var/run/opensim | 45 | sudo chmod 42770 /var/run/opensim |
43 | sudo mkdir -p $OSPATH/backups $OSPATH/caches/assetcache $OSPATH/config $OSPATH/setup | 46 | sudo mkdir -p $OSPATH/backups $OSPATH/caches/assetcache $OSPATH/config $OSPATH/setup |
44 | sudo chown opensim:opensim $OSPATH | 47 | sudo chown opensim:opensim $OSPATH |
45 | sudo chown -R opensim:opensim $OSPATH | 48 | sudo chown -R opensim:opensim $OSPATH |
@@ -111,7 +114,7 @@ sed -i 's@CacheDirectory = ./assetcache@CacheDirectory = caches/assetcache@' Flo | |||
111 | cd ../../.. | 114 | cd ../../.. |
112 | 115 | ||
113 | # Setting screen to be suid. EWWWWWW!!! Security hole!! | 116 | # Setting screen to be suid. EWWWWWW!!! Security hole!! |
114 | #ImReallyParanoid="true" | 117 | ImReallyParanoid="true" |
115 | if [ "x$ImReallyParanoid" = "x" ] | 118 | if [ "x$ImReallyParanoid" = "x" ] |
116 | then | 119 | then |
117 | sudo chmod u+s /usr/bin/screen | 120 | sudo chmod u+s /usr/bin/screen |
diff --git a/opensim.tmux.conf b/opensim.tmux.conf new file mode 100644 index 0000000..f264f8a --- /dev/null +++ b/opensim.tmux.conf | |||
@@ -0,0 +1,47 @@ | |||
1 | set-option -g prefix C-a | ||
2 | unbind-key C-b | ||
3 | bind-key C-a send-prefix | ||
4 | |||
5 | # r reloads the configuration, handy | ||
6 | bind r source-file ~/.tmux.conf | ||
7 | |||
8 | unbind % # Remove default binding since we’re replacing them. | ||
9 | bind | split-window -h | ||
10 | bind - split-window -v | ||
11 | |||
12 | set-option -g bell-action any | ||
13 | set-option -g bell-on-alert on | ||
14 | |||
15 | set-option -g history-limit 100000 | ||
16 | |||
17 | set-option -g mouse-resize-pane on | ||
18 | set-option -g mouse-select-pane on | ||
19 | set-option -g mouse-select-window on | ||
20 | set-option -g mouse-utf8 on | ||
21 | |||
22 | #set-option -g set-remain-on-exit on | ||
23 | set-option -g set-titles on | ||
24 | set-option -g set-titles-string '#W' | ||
25 | |||
26 | set-option -g status-interval 1 | ||
27 | set-option -g status-justify centre | ||
28 | set-option -g status-utf8 on | ||
29 | |||
30 | set-option -g status-left-length 80 | ||
31 | set-option -g status-left '[#H #S:(#I:#T/#W).#P #F]' | ||
32 | set-option -g status-right-length 80 | ||
33 | set-option -g status-right '%F #(uptime) %T' | ||
34 | |||
35 | set-option -g visual-activity on | ||
36 | set-option -g visual-content on | ||
37 | set-option -g visual-silence on | ||
38 | |||
39 | set-option -gw clock-mode-style 24 | ||
40 | set-option -gw mode-mouse on | ||
41 | |||
42 | # Highlight active window | ||
43 | set-option -gw window-status-current-bg red | ||
44 | |||
45 | # Set window notifications | ||
46 | set-option -gw monitor-activity on | ||
47 | |||
@@ -2,8 +2,9 @@ | |||
2 | 2 | ||
3 | USER=$(whoami) | 3 | USER=$(whoami) |
4 | console_name="OpenSim_console" | 4 | console_name="OpenSim_console" |
5 | screen_session=opensim/${console_name} | 5 | screen_command="tmux -S /var/run/opensim/opensim-tmux.socket" |
6 | screen_check="screen -ls opensim/" | 6 | screen_session=${console_name} |
7 | screen_window="${screen_command} select-window -t ${screen_session}" | ||
7 | osversion="current" | 8 | osversion="current" |
8 | bindir=/opt/opensim/${osversion}/bin | 9 | bindir=/opt/opensim/${osversion}/bin |
9 | quiet="" | 10 | quiet="" |
@@ -30,67 +31,70 @@ if [ "x$tgt" = "x" ]; then | |||
30 | exit 1 | 31 | exit 1 |
31 | fi | 32 | fi |
32 | 33 | ||
33 | if [ $USER = "opensim" ] | ||
34 | then | ||
35 | SUDO="" | ||
36 | else | ||
37 | SUDO="sudo -Hu opensim" | ||
38 | fi | ||
39 | |||
40 | # Would be nice if this worked. | 34 | # Would be nice if this worked. |
41 | export MONO_PATH=${bindir} | 35 | export 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. |
43 | cd ${bindir} | 37 | cd ${bindir} |
44 | 38 | ||
45 | if ($screen_check | grep -q ${console_name}); then | 39 | if ( ${screen_command} -q list-sessions 2>/dev/null | grep -q ${console_name}: ); then |
46 | true | 40 | true |
47 | else | 41 | else |
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} | ||
49 | fi | 51 | fi |
50 | 52 | ||
53 | inidir=/opt/opensim/config/${tgt} | ||
54 | |||
51 | if [ "x$tgt" = "xrobust" ]; then | 55 | if [ "x$tgt" = "xrobust" ]; then |
52 | exe="Robust" | 56 | exe="Robust" |
57 | title="ROBUST" | ||
58 | roboini="-inifile=${inidir}/Robust.ini" | ||
53 | else | 59 | else |
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 ))} | ||
55 | fi | 70 | fi |
56 | 71 | ||
57 | inidir=/opt/opensim/config/${tgt} | ||
58 | # Grab the first line of the sim.ini file, it should be the sim name in square brackets. | ||
59 | title=$(head -n 1 ${inidir}/Regions/sim.ini ) | ||
60 | # Strip off spaces at either end. | ||
61 | shopt -s extglob | ||
62 | title=${title##*( )} | ||
63 | title=${title%%*( )} | ||
64 | shopt -u extglob | ||
65 | # Strip off the square brackets at either end. | ||
66 | title=${title:1:$(( ${#title} - 2 ))} | ||
67 | |||
68 | case $(basename $0) in | 72 | case $(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 | ;; |
95 | esac | 99 | esac |
96 | 100 | ||
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 | |||
3 | USER=$(whoami) | ||
4 | console_name="OpenSim_console" | ||
5 | screen_session=opensim/${console_name} | ||
6 | screen_check="screen -ls opensim/" | ||
7 | osversion="current" | ||
8 | bindir=/opt/opensim/${osversion}/bin | ||
9 | quiet="" | ||
10 | |||
11 | if [ "$1" = "-q" ] | ||
12 | then | ||
13 | quiet="true" | ||
14 | shift 1 | ||
15 | fi | ||
16 | |||
17 | if [ "x$1" = "x" ]; then | ||
18 | pathname=$(pwd) | ||
19 | tgt=$(basename $pathname) | ||
20 | elif [ -d "./$1" ]; then | ||
21 | tgt=$1 | ||
22 | elif [ -d "./sim$1" ]; then | ||
23 | tgt=sim$1 | ||
24 | fi | ||
25 | |||
26 | if [ "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 | ||
31 | fi | ||
32 | |||
33 | if [ $USER = "opensim" ] | ||
34 | then | ||
35 | SUDO="" | ||
36 | else | ||
37 | SUDO="sudo -Hu opensim" | ||
38 | fi | ||
39 | |||
40 | # Would be nice if this worked. | ||
41 | export MONO_PATH=${bindir} | ||
42 | # Then we would not have to do this, and subsequently write all over the damn bin directory. | ||
43 | cd ${bindir} | ||
44 | |||
45 | if ($screen_check | grep -q ${console_name}); then | ||
46 | true | ||
47 | else | ||
48 | $SUDO screen -d -m -S ${console_name} | ||
49 | fi | ||
50 | |||
51 | if [ "x$tgt" = "xrobust" ]; then | ||
52 | exe="Robust" | ||
53 | else | ||
54 | exe="OpenSim" | ||
55 | fi | ||
56 | |||
57 | inidir=/opt/opensim/config/${tgt} | ||
58 | # Grab the first line of the sim.ini file, it should be the sim name in square brackets. | ||
59 | title=$(head -n 1 ${inidir}/Regions/sim.ini ) | ||
60 | # Strip off spaces at either end. | ||
61 | shopt -s extglob | ||
62 | title=${title##*( )} | ||
63 | title=${title%%*( )} | ||
64 | shopt -u extglob | ||
65 | # Strip off the square brackets at either end. | ||
66 | title=${title:1:$(( ${#title} - 2 ))} | ||
67 | |||
68 | case $(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 | ;; | ||
95 | esac | ||
96 | |||