From c193946f0562bf690b6ee4afe4fa7506a74ce568 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Sat, 26 Nov 2011 20:07:01 +1000 Subject: Better screen handling. --- install_opensim.sh | 3 +++ opensim-monit.conf | 2 +- opensim.screenrc | 1 - start-sim-in-rest | 71 +++++++++++++++++++++++++++++------------------------- 4 files changed, 42 insertions(+), 35 deletions(-) diff --git a/install_opensim.sh b/install_opensim.sh index 47ce76f..69c5b88 100755 --- a/install_opensim.sh +++ b/install_opensim.sh @@ -26,6 +26,9 @@ echo "Setting up OpenSim" sudo adduser --system --shell /bin/false --group opensim sudo addgroup $USER opensim sudo cp opensim.screenrc /home/opensim/.screenrc +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 mkdir -p /var/log/opensim sudo chown opensim:opensim /var/log/opensim diff --git a/opensim-monit.conf b/opensim-monit.conf index e300720..f28c76c 100644 --- a/opensim-monit.conf +++ b/opensim-monit.conf @@ -20,7 +20,7 @@ # see ../README for configuration instructions. # check process sim01 with pidfile /var/run/opensim/sim01.pid - start program = "/bin/bash -c 'cd /opt/opensim/config/sim01 && /opt/opensim/sim01/start-sim-in-rest'" + start program = "/bin/bash -c 'cd /opt/opensim/config/sim01 && /opt/opensim/sim01/start-sim-in-rest -q'" as uid opensim and gid opensim stop program = "/bin/kill -9 `cat /var/run/opensim/sim01.pid`" # if cpu usage > 300% for 4 cycles then restart diff --git a/opensim.screenrc b/opensim.screenrc index 01a4f26..961e66b 100644 --- a/opensim.screenrc +++ b/opensim.screenrc @@ -16,5 +16,4 @@ hardstatus string '%{= kw}[ %{= kb}%H%{= kw} ][%= %{= kw}%?%-Lw%?%{= kW}%n*%f %t bind 'q' quit multiuser on -acladd root diff --git a/start-sim-in-rest b/start-sim-in-rest index 4738c2e..e29490d 100755 --- a/start-sim-in-rest +++ b/start-sim-in-rest @@ -8,17 +8,18 @@ Screaming="true" #Screaming="" USER=$(whoami) +console_name="OpenSim_console" +screen_session=opensim/${console_name} +screen_check="screen -ls opensim/" +osversion="current" +bindir=/opt/opensim/${osversion}/bin +quiet="" -console_name=screen_console -if [ "$USER" = "opensim" ] +if [ "$1" = "-q" ] then - screen_session=opensim/${console_name} - screen_check="screen -ls opensim/" -else - screen_session=${console_name} - screen_check="screen -ls" + quiet="true" + shift 1 fi -osversion="current" if [ "x$1" = "x" ]; then pathname=$(pwd) @@ -36,14 +37,22 @@ if [ "x$tgt" = "x" ]; then exit 1 fi +if [ $USER = "opensim" ] +then + SUDO="" +else + SUDO="sudo -Hu opensim" +fi + +cd ${bindir} if [ "x$Screaming" = "xtrue" ] then - if ($screen_check | grep -q ${console_name}); then - echo "INFO: Screen already running" - true - else - echo "DEBUG: Starting screen" - screen -d -m -S ${console_name} + if ($screen_check | grep -q ${console_name}); then + echo "INFO: Screen already running" + true + else + echo "DEBUG: Starting screen" + $SUDO screen -d -m -S ${console_name} fi fi @@ -52,39 +61,35 @@ if [ "x$tgt" = "xrobust" ]; then else exe="OpenSim" fi + inidir=/opt/opensim/config/${tgt} -bindir=/opt/opensim/${osversion}/bin cmd="/usr/bin/mono ${exe}.exe -inidirectory=${inidir} -logconfig=${inidir}/${exe}.exe.config $NeedARest" +title=$(head -n 1 ${inidir}/Regions/sim.ini ) # Check if it's already running. if [ ! -e /var/run/opensim/${tgt} ] then if [ "x$Screaming" = "xtrue" ] then - tmpfile=`mktemp` - echo "chdir ${bindir}" > ${tmpfile} - echo "screen -t ${tgt} ${cmd}" >> ${tmpfile} - chmod a+r ${tmpfile} - rm -f ${inidir}/start.screen - cp ${tmpfile} ${inidir}/start.screen - rm ${tmpfile} - # echo "INFO: start process and connect to screen (opensim)" - screen -r ${screen_session} -p "-" -X source ${inidir}/start.screen + echo "INFO: start process and connect to screen (opensim) $title" + $SUDO screen -r ${screen_session} -p "-" -X screen -t "${title}" ${cmd} else - cd ${bindir} $cmd fi fi -# Either way, need to start up the console after. -if [ "x$Screaming" = "xtrue" ] +if [ "x$quiet" = "x" ] then - echo "Starting screen client." + # Either way, need to start up the console after. + if [ "x$Screaming" = "xtrue" ] + then + echo "Starting screen client." screen -r ${screen_session} -A -elif [ "x$NeedARest" != "x" ] -then - echo "Starting rest client." - cd ${inidir} - /usr/bin/mono ${bindir}/OpenSim.ConsoleClient.exe -logconfig=${inidir}/${exe}.exe.config + elif [ "x$NeedARest" != "x" ] + then + echo "Starting rest client." + cd ${inidir} + /usr/bin/mono ${bindir}/OpenSim.ConsoleClient.exe -logconfig=${inidir}/${exe}.exe.config + fi fi -- cgit v1.1