[openrtm-commit:03354] r3427 - in branches/RELENG_1_1/OpenRTM-aist: utils/rtm-naming win32/OpenRTM-aist/bin

openrtm @ openrtm.org openrtm @ openrtm.org
2018年 11月 1日 (木) 18:30:51 JST


Author: kawauchi
Date: 2018-11-01 18:30:51 +0900 (Thu, 01 Nov 2018)
New Revision: 3427

Added:
   branches/RELENG_1_1/OpenRTM-aist/win32/OpenRTM-aist/bin/kill-rtm-naming.bat
Modified:
   branches/RELENG_1_1/OpenRTM-aist/utils/rtm-naming/Makefile.am
   branches/RELENG_1_1/OpenRTM-aist/utils/rtm-naming/rtm-naming.in
   branches/RELENG_1_1/OpenRTM-aist/win32/OpenRTM-aist/bin/Makefile.am
   branches/RELENG_1_1/OpenRTM-aist/win32/OpenRTM-aist/bin/rtm-naming.bat
Log:
[merge] r3222,3227,3376,3381,3390-3394,3400,3402 have been merged from RELENG_1_2.

Modified: branches/RELENG_1_1/OpenRTM-aist/utils/rtm-naming/Makefile.am
===================================================================
--- branches/RELENG_1_1/OpenRTM-aist/utils/rtm-naming/Makefile.am	2018-11-01 09:21:05 UTC (rev 3426)
+++ branches/RELENG_1_1/OpenRTM-aist/utils/rtm-naming/Makefile.am	2018-11-01 09:30:51 UTC (rev 3427)
@@ -20,7 +20,7 @@
 	cat rtm-naming.in >> $@
 	chmod 755 $@
 
-EXTRA_DIST = rtm-naming.in
+EXTRA_DIST = rtm-naming.in 
 
 clean-local:
 	rm -rf rtm-naming *~ *core

Modified: branches/RELENG_1_1/OpenRTM-aist/utils/rtm-naming/rtm-naming.in
===================================================================
--- branches/RELENG_1_1/OpenRTM-aist/utils/rtm-naming/rtm-naming.in	2018-11-01 09:21:05 UTC (rev 3426)
+++ branches/RELENG_1_1/OpenRTM-aist/utils/rtm-naming/rtm-naming.in	2018-11-01 09:30:51 UTC (rev 3427)
@@ -3,15 +3,15 @@
 #  @brief OpenRTM-aist name server launcher
 #  @date $Date: 2005-05-12 09:06:19 $
 #  @author Noriaki Ando <n-ando at aist.go.jp>
-# 
-#  Copyright (C) 2003-2011
+#
+#  Copyright (C) 2003-2018
 #      Intelligent Systems Research Institute,
 #      National Institute of
 #          Advanced Industrial Science and Technology (AIST), Japan
 #      All rights reserved.
-# 
+#
 #  $Id$
-# 
+#
 
 pname=`basename $cosnames`
 hostname=`hostname`
@@ -20,12 +20,52 @@
 
 usage()
 {
-	cat<<EOF
-Usage: rtm-naming port_number
+    cat<<EOF
+
+  Usage:
+    $(basename $0) [-p port_number] [-f] [-w password] [h]
+
+  Example:
+    $(basename $0) -p 8888 -f
+      Force running naming service on port 8888
+
+  Options:
+    -p         Port number of naming service. (default 2809)
+    -f         Force kill current running naming service.
+    -k         Stop existing naming service.
+    -w         Current user's passoword to restart naming service.
+    -h         Print this help.
+
 EOF
 }
 
+get_opt()
+{
+    # Global variables
+    FORCEKILL=""
+    PASSWORD=""
+    PORT=2809
+    if test $# -eq 0 ; then
+        PORT=2809
+    fi
 
+    while getopts p:fkw:h OPT
+    do
+        case $OPT in
+            p) PORT=$OPTARG
+                ;;
+            f) FORCEKILL="YES"
+                ;;
+            k) STOPNAMESERVICE="YES"
+                ;;
+            w) PASSWORD=$OPTARG
+                ;;
+            h) usage
+                exit 1
+                ;;
+        esac
+    done
+}
 #
 # debug <text>
 #
@@ -36,7 +76,7 @@
 debug()
 {
     if test "x$DEBUG" != "x"; then
-	echo $*
+        echo $*
     fi
 }
 
@@ -53,17 +93,21 @@
 get_pid_of_nsport()
 {
     _port=$1
-    debug "netstat -tanp 2> /dev/null | grep $_port | awk '{print $7;}'"
-    netstat_tanp=`netstat -tanp`
-    _netstat=`netstat -tanp 2> /dev/null | grep $_port | awk '{if($7!="-"){print $7;}}'`
-    debug "A possible process that is using $port port:" $_netstat
+    debug "netstat -tlnp 2> /dev/null | grep $_port | awk '{print $7;}'"
+    netstat_tanp=`netstat -tlnp`
+    if test "x$PASSWORD" = "x"; then
+        _netstat=`sudo netstat -tlnp 2> /dev/null | grep $_port | awk '{if($7!="-"){print $7;}}'`
+    else
+        _netstat=`echo $PASSWORD | sudo -S netstat -tlnp 2> /dev/null | grep $_port | awk '{if($7!="-"){print $7;}}'`
+    fi
+    debug "A possible process that is using $_port port:" $_netstat
     if test "x$_netstat" = "x"; then
-	debug "No process using port number ${_port} on the system."
-	return 1
+        debug "No process using port number ${_port} on the system."
+        return 1
     fi
     if test "x$_netstat" = "x"; then
-	debug "Process information could not be identified."
-	return 1
+        debug "Process information could not be identified."
+        return 1
     fi
 
     _pid=`echo $_netstat | awk 'BEGIN{FS="/";}{print $1;}'`
@@ -142,6 +186,22 @@
     fi
 }
 
+delete_omninames_files()
+{
+    if test "x$PASSWORD" = "x" ; then
+        rm -f ./omninames-$hostname.log
+        rm -f ./omninames-$hostname.bak
+        rm -f ./omninames-$hostname.dat
+    else
+        echo $PASSWORD | sudo -S rm -f ./omninames-$hostname.log
+        echo $PASSWORD | sudo -S rm -f ./omninames-$hostname.bak
+        echo $PASSWORD | sudo -S rm -f ./omninames-$hostname.dat
+        echo $PASSWORD | sudo -S rm -f /var/lib/omniorb/omninames-$hostname.log
+        echo $PASSWORD | sudo -S rm -f /var/lib/omniorb/omninames-$hostname.bak
+        echo $PASSWORD | sudo -S rm -f /var/lib/omniorb/omninames-$hostname.dat
+    fi
+    debug "omninames-$hostname files deleted."
+}
 
 #
 # stop_existing_ns
@@ -161,7 +221,8 @@
 #
 stop_existing_ns()
 {
-    get_pid_of_nsport $port
+    debug "---stop_existing_ns"
+    get_pid_of_nsport $PORT
     if test $? -eq 0; then
 	debug "The Process information using the port could be obtained."
         # If "port" is used by other program -> abort
@@ -189,37 +250,88 @@
 
     # omniNames is not started by init script
     if test $? -ne 0; then
-	debug "$pname might not be started from init script."
-	if test "x$pid_of_nsport" != "x" ; then
-	    echo "$pname (pid: $pid_of_nsport) is running"
-	    read -p "Kill anyway and start $pname again? (y/N)" killns
-	    if test "x$killns" = "xy" -o  "x$killns" = "xY"; then
-		pkill -f $pname
-		echo "$pname (pid: $pid_of_nsport) are killed"
-		return 0
-	    fi
-	    echo "Aborting"
-	    exit 1
-	fi
-	echo "No running $pname found. The process using the port $port "
-	echo "cannot be estimated. Arboting"
-	exit 1
+        debug "$pname might not be started from init script."
+        if test "x$pid_of_nsport" != "x" ; then
+            echo "$pname (pid: $pid_of_nsport) is running"
+
+            # Restart naming service
+            if test "x$FORCEKILL" = "x" ; then
+                if test "x$STOPNAMESERVICE" = "x" ; then
+		            read -p "Kill anyway and start $pname again? (y/N)" killns
+	            else
+                    read -p "Kill anyway? (y/N)" killns
+		        fi
+                if test "x$killns" != "xy" -a  "x$killns" != "xY"; then
+                    echo "Aborting"
+                    exit 1
+                fi
+	        fi
+            if test "x$PASSWORD" = "x" ; then
+                sudo pkill -f $pname
+                sudo rm -f /var/run/$pname.pid 
+            else
+                echo $PASSWORD | sudo -S pkill -f $pname
+                echo $PASSWORD | sudo -S rm -f /var/run/$pname.pid
+            fi
+            echo "$pname (pid: $pid_of_nsport) are killed"
+            debug "$pname (pid: $pid_of_nsport) are killed"
+            debug "/var/run/$pname.pid  are deleted"
+            delete_omninames_files
+            return 0
+        fi
+        echo "No running $pname found. The process using the port $PORT "
+        echo "cannot be estimated. Arboting"
+        exit 1
     fi
-
     # omniNames is started by init script
     echo "omniNames might be started $init_script."
-    echo "Stop it (password for sudo is required.)"
-    read -p "and start omniNames by rtm-naming? (y/N)" startns
 
-    if test "x$startns" != "xy" -a "x$startns" != "xY" ; then
-	echo "Aborted."
-	exit 1
+    if test "x$FORCEKILL" = "x" && test "x$STOPNAMESERVICE" = "x" ; then
+        echo "Stop it (password for sudo is required.)"
+        read -p "and start omniNames by rtm-naming? (y/N)" startns
+        if test "x$startns" != "xy" -a "x$startns" != "xY" ; then
+            echo "Aborted."
+            exit 1
+        fi
     fi
     echo "Stopping omniNames by $init_script."
-    sudo $init_script stop
+    if test "x$PASSWORD" = "x" ; then
+       sudo $init_script stop
+       sudo rm -f /var/run/$pname.pid 
+    else
+        echo $PASSWORD | sudo -S $init_script stop
+        echo $PASSWORD | sudo -S rm -f /var/run/$pname.pid
+    fi
+    debug "$init_script stop"
+    debug "/var/run/$pname.pid  are deleted"
+    delete_omninames_files
     return 0
 }
 
+fedora_omninames()
+{
+    _param=$1
+    if test "x$PASSWORD" = "x" ; then
+        sudo service $pname $_param 
+    else
+        echo $PASSWORD | sudo -S service $pname $_param 
+    fi
+    debug "OMNI Naming services $_param: $pname"
+    sleep 1
+    pids=`pgrep $pname`
+    if test "x$pids" != "x" ; then
+        debug "omniNames process ID:" $pids
+        omnip=`ps $pids | wc -l`
+        if test $omnip -gt 1; then
+            echo "omniNames properly started"
+            exit 0
+        fi
+    else
+        debug "omniNames was not properly started."
+    fi
+    return 0 
+}
+
 #------------------------------------------------------------
 # omniNames specific functions
 #------------------------------------------------------------
@@ -231,20 +343,28 @@
 #
 start_omninames()
 {
-    echo 'Starting omniORB omniNames: '$hostname':'$port
-    rm -f ./omninames-$hostname.log
-    rm -f ./omninames-$hostname.bak
-    rm -f ./omninames-$hostname.dat
-    $cosnames -start $port -logdir $currdir &
-    ret=$!
+    debug "---start_omninames"
+    echo 'Starting omniORB omniNames: '$hostname':'$PORT
+    init_script=`grep $orb /etc/init.d/* | awk 'BEGIN{FS=":";}{if(FNR==1){print $1;}}'`
+    if test "x$PASSWORD" = "x" ; then
+        sudo $init_script start
+    else
+        echo $PASSWORD | sudo -S $init_script start
+    fi
+    debug "$init_script start"
+    pids=`pgrep $pname`
     sleep 1
-    debug "return code of omniNames:" $ret
-    omnip=`ps $! | wc -l`
-    if test $omnip -gt 1; then
-	echo "omniNames properly started"
-	exit 0
+    if test "x$pids" != "x" ; then
+        debug "omniNames process ID:" $pids
+        omnip=`ps $pids | wc -l`
+        if test $omnip -gt 1; then
+            echo "omniNames properly started"
+            exit 0
+        fi
+    else
+        debug "omniNames was not properly started."
     fi
-    return 1
+    return 0
 }
 
 omniname()
@@ -252,16 +372,27 @@
     # Check cosname variable is properly set
     check_cosname
 
-    # Starting omniNames
-    start_omninames
-    echo "omniNames was not properly started."
+    # Starting omniNames (Fedora)
+    if test "x$STOPNAMESERVICE" = "x" && test -f /etc/fedora-release ; then
+      fedora_omninames start
+      fedora_omninames restart
+      return 0
+    fi
 
+    # Starting omniNames (Debian)
+    if test "x$STOPNAMESERVICE" = "x" ; then
+      start_omninames
+      echo "omniNames was not properly started."
+    fi
+
     # Stopping existing name service
     stop_existing_ns
 
     # Try to start omniNames again
-    start_omninames
-    echo "omniNames was not properly started."
+    if test "x$STOPNAMESERVICE" = "x" ; then
+      start_omninames
+      echo "omniNames was not properly started."
+    fi
 }
 
 #------------------------------------------------------------
@@ -279,8 +410,8 @@
 	echo "TAO Naming_Service not found. Aborting."
 	exit 1
     fi
-    echo 'Starting TAO Naming_Service: '$hostname':'$port
-    $cosnames -m 0 -ORBListenEndpoints iiop://:$port &
+    echo 'Starting TAO Naming_Service: '$hostname':'$PORT
+    $cosnames -m 0 -ORBListenEndpoints iiop://:$PORT &
     ret=$!
     sleep 1
     debug "return code of TAO Naming_Service:" $ret
@@ -315,11 +446,7 @@
 #------------------------------------------------------------
 # main
 #------------------------------------------------------------
-if test $# -gt 0; then
-    port=$1
-else
-    port=2809
-fi
+get_opt $@
 
 case $orb in
 	omniORB)

Modified: branches/RELENG_1_1/OpenRTM-aist/win32/OpenRTM-aist/bin/Makefile.am
===================================================================
--- branches/RELENG_1_1/OpenRTM-aist/win32/OpenRTM-aist/bin/Makefile.am	2018-11-01 09:21:05 UTC (rev 3426)
+++ branches/RELENG_1_1/OpenRTM-aist/win32/OpenRTM-aist/bin/Makefile.am	2018-11-01 09:30:51 UTC (rev 3427)
@@ -41,4 +41,5 @@
 
 EXTRA_DIST = \
 	rtm-naming.bat \
+	kill-rtm-naming.bat \
 	rtc.conf

Copied: branches/RELENG_1_1/OpenRTM-aist/win32/OpenRTM-aist/bin/kill-rtm-naming.bat (from rev 3376, branches/RELENG_1_2/OpenRTM-aist/win32/OpenRTM-aist/bin/kill-rtm-naming.bat)
===================================================================
--- branches/RELENG_1_1/OpenRTM-aist/win32/OpenRTM-aist/bin/kill-rtm-naming.bat	                        (rev 0)
+++ branches/RELENG_1_1/OpenRTM-aist/win32/OpenRTM-aist/bin/kill-rtm-naming.bat	2018-11-01 09:30:51 UTC (rev 3427)
@@ -0,0 +1,7 @@
+ at echo off
+
+TASKLIST | FIND "omniNames.exe" > NUL
+IF NOT ERRORLEVEL 1  (
+        TASKKILL /F /IM omniNames.exe
+)
+

Modified: branches/RELENG_1_1/OpenRTM-aist/win32/OpenRTM-aist/bin/rtm-naming.bat
===================================================================
--- branches/RELENG_1_1/OpenRTM-aist/win32/OpenRTM-aist/bin/rtm-naming.bat	2018-11-01 09:21:05 UTC (rev 3426)
+++ branches/RELENG_1_1/OpenRTM-aist/win32/OpenRTM-aist/bin/rtm-naming.bat	2018-11-01 09:30:51 UTC (rev 3427)
@@ -1,5 +1,7 @@
 @echo off
 
+call kill-rtm-naming.bat
+
 set cosnames="omninames"
 set orb="omniORB"
 set port=%1



openrtm-commit メーリングリストの案内