[openrtm-commit:03365] r3438 - trunk/OpenRTM-aist/utils/rtm-naming
openrtm @ openrtm.org
openrtm @ openrtm.org
2018年 11月 7日 (水) 20:05:51 JST
Author: kawauchi
Date: 2018-11-07 20:05:51 +0900 (Wed, 07 Nov 2018)
New Revision: 3438
Modified:
trunk/OpenRTM-aist/utils/rtm-naming/rtm-naming.in
Log:
[merge] r3435-3436 have been merged from RELENG_1_2. Merge defect of r3395 has been fixed.
Modified: trunk/OpenRTM-aist/utils/rtm-naming/rtm-naming.in
===================================================================
--- trunk/OpenRTM-aist/utils/rtm-naming/rtm-naming.in 2018-11-07 08:10:49 UTC (rev 3437)
+++ trunk/OpenRTM-aist/utils/rtm-naming/rtm-naming.in 2018-11-07 11:05:51 UTC (rev 3438)
@@ -93,18 +93,19 @@
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
+ echo "No process using port number ${_port} on the system."
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
- fi
_pid=`echo $_netstat | awk 'BEGIN{FS="/";}{print $1;}'`
pname_of_nsport=`echo $_netstat | awk 'BEGIN{FS="/";}{print $2;}'`
@@ -192,14 +193,74 @@
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."
}
#
+# specified_port_used_check
+#
+# Find a process which is using specified port.
+#
+specified_port_used_check()
+{
+ 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
+
+ pids=`pgrep $pname`
+ matchflag=0
+ for p in $pids; do
+ if test "x$pid_of_nsport" = "x$p"; then
+ matchflag=1
+ fi
+ done
+ if test $matchflag -eq 0; then
+ echo "$pname_of_nsport (not $pname) is using the port."
+ echo "Starting $pname aborted. Please use the other port."
+ exit 1
+ fi
+ else
+ debug "The process information using the port could not be obtained."
+ exit 1
+ fi
+}
+
+#
+# stop omninames by init script
+#
+# Process is started from the init script, it tries to stop it
+# by the script.
+#
+stop_omninames_by_init_script()
+{
+ echo "omniNames might be started $init_script."
+
+ 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."
+ 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
+
+}
+
+#
# stop_existing_ns
#
# This function try to stop existing nameing service.
@@ -218,30 +279,11 @@
stop_existing_ns()
{
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
- pids=`pgrep $pname`
- matchflag=0
- for p in $pids; do
- if test "x$pid_of_nsport" = "x$p"; then
- matchflag=1
- fi
- done
- if test $matchflag -eq 0; then
- echo "$pname_of_nsport (not $pname) is using the port."
- echo "Starting $pname aborted. Please use the other port."
- exit 1
- fi
- else
- debug "The process information using the port could not be obtained."
- pname_of_nsport=$pname
- pid_of_nsport=`pgrep $pname`
- fi
+ # Find a process which is using specified port.
+ specified_port_used_check
-
+ # Started form /etc/init.d/ script?
is_started_from_init $pname_of_nsport $pid_of_nsport
# omniNames is not started by init script
@@ -257,21 +299,18 @@
else
read -p "Kill anyway? (y/N)" killns
fi
- if test "x$killns" != "xy" -o "x$killns" != "xY"; then
+ 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
+ sudo kill -9 $pid_of_nsport
else
- echo $PASSWORD | sudo -S pkill -f $pname
- echo $PASSWORD | sudo -S rm -f /var/run/$pname.pid
+ echo $PASSWORD | sudo -S kill -9 $pid_of_nsport
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
@@ -280,54 +319,10 @@
exit 1
fi
# omniNames is started by init script
- echo "omniNames might be started $init_script."
-
- 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."
- 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
+ stop_omninames_by_init_script
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
#------------------------------------------------------------
@@ -341,47 +336,21 @@
{
debug "---start_omninames"
echo 'Starting omniORB omniNames: '$hostname':'$PORT
-<<<<<<< .working
- rm -f ./omninames-$hostname.log
- rm -f ./omninames-$hostname.bak
- rm -f ./omninames-$hostname.dat
- $cosnames -start $PORT -logdir $currdir &
-||||||| .merge-left.r3391
+ delete_omninames_files
if test "x$PASSWORD" = "x" ; then
- rm -f ./omninames-$hostname.log
- rm -f ./omninames-$hostname.bak
- rm -f ./omninames-$hostname.dat
$cosnames -start $PORT -logdir $currdir &
- echo "$cosnames -start $PORT -logdir $currdir &"
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 $cosnames -start $PORT -logdir $currdir &
- echo "sudo $cosnames -start $PORT -logdir $currdir &"
fi
-=======
- 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
->>>>>>> .merge-right.r3394
- debug "$init_script start"
- pids=`pgrep $pname`
+ ret=$!
sleep 1
- 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."
+ debug "return code of omniNames:" $ret
+ omnip=`ps $! | wc -l`
+ if test $omnip -gt 1; then
+ echo "omniNames properly started"
+ exit 0
fi
- return 0
+ return 1
}
omniname()
@@ -389,14 +358,7 @@
# Check cosname variable is properly set
check_cosname
- # 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)
+ # Starting omniNames
if test "x$STOPNAMESERVICE" = "x" ; then
start_omninames
echo "omniNames was not properly started."
openrtm-commit メーリングリストの案内