]> gitweb.fluxo.info Git - kvmx.git/commitdiff
Enhanced nohup strategy for kvmx-shell
authorSilvio Rhatto <rhatto@riseup.net>
Fri, 15 Jun 2018 00:01:56 +0000 (21:01 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Fri, 15 Jun 2018 00:01:56 +0000 (21:01 -0300)
kvmx

diff --git a/kvmx b/kvmx
index 8de8d232a76c96a91ff1c85c58fb6d15fdb36211..6386e7c2017b6d4b63d9e30ad952cdb201478357 100755 (executable)
--- a/kvmx
+++ b/kvmx
@@ -1772,6 +1772,7 @@ function kvmx_version {
 
 # Shell
 function kvmx_shell {
+  local tail=""
   local restricted="$1"
   local restricted_actions=":status:start:stop:poweroff:suspend:resume:console:monitor"
         restricted_actions="$restricted_actions:wipe:shred:app_base:version:list_image:kill:"
@@ -1794,8 +1795,14 @@ function kvmx_shell {
         else
           if [ "${STDIN[0]}" == "up" ] || [ "${STDIN[0]}" == "start" ] || [ "${STDIN[0]}" == "restart" ]; then
             # Process command, nohup version, stdout and stderr are redirected to a file
-            nohup $APP_BASE/kvmx ${STDIN[0]} $VM ${STDIN[@]:1} >> $LOG_DIR/nohup 2>&1 &
-            tail -F $LOG_DIR/nohup &
+            nohup $APP_BASE/kvmx ${STDIN[0]} $VM ${STDIN[@]:1} < /dev/null >> $LOG_DIR/nohup 2>&1 &
+
+            sleep 1
+            if [ -e "$LOG_DIR/nohup" ] && [ -z "$tail" ]; then
+              tail -F $LOG_DIR/nohup &
+              tail="$1"
+            fi
+            sleep 1
 
             # Process command, disown version, stdout are preserved
             #$APP_BASE/kvmx ${STDIN[0]} $VM ${STDIN[@]:1} &
@@ -1807,7 +1814,7 @@ function kvmx_shell {
       else
         if [ "${STDIN[0]}" == "up" ] || [ "${STDIN[0]}" == "start" ] || [ "${STDIN[0]}" == "restart" ]; then
           # Process command, nohup version
-          nohup $APP_BASE/kvmx ${STDIN[0]} $VM ${STDIN[@]:1} >> $LOG_DIR/nohup 2>&1 &
+          nohup $APP_BASE/kvmx ${STDIN[0]} $VM ${STDIN[@]:1} < /dev/null >> $LOG_DIR/nohup 2>&1 &
           tail -F $LOG_DIR/nohup &
 
           # Process command, disown version
@@ -1819,6 +1826,11 @@ function kvmx_shell {
       fi
     fi
   done
+
+  if [ ! -z "$tail" ]; then
+    kill $tail &> /dev/null
+    rm -f $LOG_DIR/nohup
+  fi
 }
 
 # Xrandr integration