From 85ae70d895f784632e4a6041024034dbe692dac8 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Mon, 12 Dec 2011 19:24:18 +1000 Subject: Convert to using tmux, though the old screen stuff is still there. --- install_opensim.sh | 9 +++-- opensim.tmux.conf | 47 ++++++++++++++++++++++++++ start-sim | 58 ++++++++++++++++++--------------- start-sim-screen | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 180 insertions(+), 30 deletions(-) create mode 100644 opensim.tmux.conf create mode 100755 start-sim-screen 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" USER=$(whoami) VERSION_CONTROL="off" -sudo apt-get install mysql-server screen mono-complete monit mc +sudo apt-get install mysql-server tmux screen mono-complete monit mc sudo /etc/init.d/mysql restart echo "Setting up mySQL" @@ -34,12 +34,15 @@ sudo chown $USER /home/opensim/.screenrc echo -e "acladd root,$USER\n" >> /home/opensim/.screenrc sudo chown opensim:opensim /home/opensim/.screenrc sudo chmod 644 /home/opensim/.screenrc +sudo cp opensim.tmux.conf /home/opensim/.tmux.conf +sudo chown $USER /home/opensim/.tmux.conf +sudo chmod 644 /home/opensim/.tmux.conf sudo mkdir -p /var/log/opensim sudo chown opensim:opensim /var/log/opensim sudo chmod 757 /var/log/opensim sudo mkdir -p /var/run/opensim sudo chown opensim:opensim /var/run/opensim -sudo chmod 757 /var/run/opensim +sudo chmod 42770 /var/run/opensim sudo mkdir -p $OSPATH/backups $OSPATH/caches/assetcache $OSPATH/config $OSPATH/setup sudo chown opensim:opensim $OSPATH sudo chown -R opensim:opensim $OSPATH @@ -111,7 +114,7 @@ sed -i 's@CacheDirectory = ./assetcache@CacheDirectory = caches/assetcache@' Flo cd ../../.. # Setting screen to be suid. EWWWWWW!!! Security hole!! -#ImReallyParanoid="true" +ImReallyParanoid="true" if [ "x$ImReallyParanoid" = "x" ] then 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 @@ +set-option -g prefix C-a +unbind-key C-b +bind-key C-a send-prefix + +# r reloads the configuration, handy +bind r source-file ~/.tmux.conf + +unbind % # Remove default binding since we’re replacing them. +bind | split-window -h +bind - split-window -v + +set-option -g bell-action any +set-option -g bell-on-alert on + +set-option -g history-limit 100000 + +set-option -g mouse-resize-pane on +set-option -g mouse-select-pane on +set-option -g mouse-select-window on +set-option -g mouse-utf8 on + +#set-option -g set-remain-on-exit on +set-option -g set-titles on +set-option -g set-titles-string '#W' + +set-option -g status-interval 1 +set-option -g status-justify centre +set-option -g status-utf8 on + +set-option -g status-left-length 80 +set-option -g status-left '[#H #S:(#I:#T/#W).#P #F]' +set-option -g status-right-length 80 +set-option -g status-right '%F #(uptime) %T' + +set-option -g visual-activity on +set-option -g visual-content on +set-option -g visual-silence on + +set-option -gw clock-mode-style 24 +set-option -gw mode-mouse on + +# Highlight active window +set-option -gw window-status-current-bg red + +# Set window notifications +set-option -gw monitor-activity on + diff --git a/start-sim b/start-sim index 12c8f8f..df66790 100755 --- a/start-sim +++ b/start-sim @@ -2,8 +2,9 @@ USER=$(whoami) console_name="OpenSim_console" -screen_session=opensim/${console_name} -screen_check="screen -ls opensim/" +screen_command="tmux -S /var/run/opensim/opensim-tmux.socket" +screen_session=${console_name} +screen_window="${screen_command} select-window -t ${screen_session}" osversion="current" bindir=/opt/opensim/${osversion}/bin quiet="" @@ -30,67 +31,70 @@ if [ "x$tgt" = "x" ]; then exit 1 fi -if [ $USER = "opensim" ] -then - SUDO="" -else - SUDO="sudo -Hu opensim" -fi - # Would be nice if this worked. export MONO_PATH=${bindir} # Then we would not have to do this, and subsequently write all over the damn bin directory. cd ${bindir} -if ($screen_check | grep -q ${console_name}); then +if ( ${screen_command} -q list-sessions 2>/dev/null | grep -q ${console_name}: ); then true else - $SUDO screen -d -m -S ${console_name} + if [ $USER = "opensim" ] + then + SUDO="" + else + SUDO="sudo -Hu opensim" + fi + # 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. + # 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. + $SUDO ${screen_command} new-session -d -s ${console_name} fi +inidir=/opt/opensim/config/${tgt} + if [ "x$tgt" = "xrobust" ]; then exe="Robust" + title="ROBUST" + roboini="-inifile=${inidir}/Robust.ini" else exe="OpenSim" + # Grab the first line of the sim.ini file, it should be the sim name in square brackets. + title=$(head -n 1 ${inidir}/Regions/sim.ini ) + # Strip off spaces at either end. + shopt -s extglob + title=${title##*( )} + title=${title%%*( )} + shopt -u extglob + # Strip off the square brackets at either end. + title=${title:1:$(( ${#title} - 2 ))} fi -inidir=/opt/opensim/config/${tgt} -# Grab the first line of the sim.ini file, it should be the sim name in square brackets. -title=$(head -n 1 ${inidir}/Regions/sim.ini ) -# Strip off spaces at either end. -shopt -s extglob -title=${title##*( )} -title=${title%%*( )} -shopt -u extglob -# Strip off the square brackets at either end. -title=${title:1:$(( ${#title} - 2 ))} - case $(basename $0) in "start-sim") - cmd="/usr/bin/mono ${bindir}/${exe}.exe -inidirectory=${inidir} -logconfig=${inidir}/${exe}.exe.config" + cmd="/usr/bin/mono ${bindir}/${exe}.exe -inidirectory=${inidir} -logconfig=${inidir}/${exe}.exe.config ${roboini}" # Check if it's already running. if [ ! -e /var/run/opensim/${tgt}.pid ] then - $SUDO screen -r ${screen_session} -p "-" -X screen -t "[${title}]" ${cmd} + ${screen_command} new-window -dn "[${title}]" -t "${screen_session}" "${cmd}" fi ;& "sim-console") if [ "x$quiet" = "x" ] then - screen -r ${screen_session} -p "[${title}]" -A + ${screen_window}:"[${title}]" \; attach-session -t "${screen_session}" fi ;; "backup-sim") # Substitute underscores for spaces in the title, then add the full date and time to create the OAR file name. cmd="save oar ${inidir}/../../backups/${title// /_}-$(date '+%F_%T').oar" - $SUDO screen -r opensim/OpenSim_console -p "[${title}]" -X stuff "${cmd}$(/bin/echo -ne '\015')" + ${screen_window}:"[${title}]" \; send-keys "${cmd}" Enter ;; "stop-sim") - $SUDO screen -r opensim/OpenSim_console -p "[${title}]" -X stuff "shutdown$(/bin/echo -ne '\015')" + ${screen_window}:"[${title}]" \; send-keys "shutdown" Enter ;; esac 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 @@ +#!/bin/bash + +USER=$(whoami) +console_name="OpenSim_console" +screen_session=opensim/${console_name} +screen_check="screen -ls opensim/" +osversion="current" +bindir=/opt/opensim/${osversion}/bin +quiet="" + +if [ "$1" = "-q" ] +then + quiet="true" + shift 1 +fi + +if [ "x$1" = "x" ]; then + pathname=$(pwd) + tgt=$(basename $pathname) +elif [ -d "./$1" ]; then + tgt=$1 +elif [ -d "./sim$1" ]; then + tgt=sim$1 +fi + +if [ "x$tgt" = "x" ]; then + echo "usage:" + echo " $ $(basename $0) " + echo "where is one of: " robust sim[0-9][0-9] + exit 1 +fi + +if [ $USER = "opensim" ] +then + SUDO="" +else + SUDO="sudo -Hu opensim" +fi + +# Would be nice if this worked. +export MONO_PATH=${bindir} +# Then we would not have to do this, and subsequently write all over the damn bin directory. +cd ${bindir} + +if ($screen_check | grep -q ${console_name}); then + true +else + $SUDO screen -d -m -S ${console_name} +fi + +if [ "x$tgt" = "xrobust" ]; then + exe="Robust" +else + exe="OpenSim" +fi + +inidir=/opt/opensim/config/${tgt} +# Grab the first line of the sim.ini file, it should be the sim name in square brackets. +title=$(head -n 1 ${inidir}/Regions/sim.ini ) +# Strip off spaces at either end. +shopt -s extglob +title=${title##*( )} +title=${title%%*( )} +shopt -u extglob +# Strip off the square brackets at either end. +title=${title:1:$(( ${#title} - 2 ))} + +case $(basename $0) in + "start-sim") + cmd="/usr/bin/mono ${bindir}/${exe}.exe -inidirectory=${inidir} -logconfig=${inidir}/${exe}.exe.config" + + # Check if it's already running. + if [ ! -e /var/run/opensim/${tgt}.pid ] + then + $SUDO screen -r ${screen_session} -p "-" -X screen -t "[${title}]" ${cmd} + fi + ;& + + "sim-console") + if [ "x$quiet" = "x" ] + then + screen -r ${screen_session} -p "[${title}]" -A + fi + ;; + + "backup-sim") + # Substitute underscores for spaces in the title, then add the full date and time to create the OAR file name. + cmd="save oar ${inidir}/../../backups/${title// /_}-$(date '+%F_%T').oar" + $SUDO screen -r opensim/OpenSim_console -p "[${title}]" -X stuff "${cmd}$(/bin/echo -ne '\015')" + ;; + + "stop-sim") + $SUDO screen -r opensim/OpenSim_console -p "[${title}]" -X stuff "shutdown$(/bin/echo -ne '\015')" + ;; +esac + -- cgit v1.1