Re: [devel] [PATCH 1/1] base: Try again for opensafd stop [#2459]

2017-06-02 Thread Anders Widell
Note that we maybe should avoid adding new a dependency towards the 
inotifywait tool...


regards,

Anders Widell


On 06/02/2017 02:38 PM, Rafael Odzakow wrote:
Thanks I am trying to implement the suggestions and will send out a 
new patch soon.



On 06/02/2017 08:51 AM, Hans Nordebäck wrote:

Hi Rafael,

I forgot one thing, not to say that you should change your patch, 
only as an example as we use inotify in opensaf,


the following may also work:

wait_for_lockfile_clear() {
  inotifywait -q -t 20 -e delete_self $lockfile_inprogress
  if [ $? = 2 ]; then
return 1
  else
touch $lockfile_inprogress
return 0
  fi
}

/Hans

On 06/02/2017 07:27 AM, Hans Nordebäck wrote:

ack, code review only.

Minor comments, in current opensafd script, the test and create of 
the lockfile is not atomic, so there is


a window for race. Perhaps we can move the creation of the lockfile 
to function "wait_for_lockfile_clear",


and make the  test and create of the lockfile atomic?

/HansN


On 06/01/2017 02:37 PM, Rafael Odzakow wrote:

Internally opensafd creates a lock file during start/stop to avoid
parallel execution. Wait for this lockfile to be released when a 
call to

opensafd stop is done.
---
  src/nid/opensafd.in | 19 +--
  1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/src/nid/opensafd.in b/src/nid/opensafd.in
index e7683bd7e..df90331a6 100644
--- a/src/nid/opensafd.in
+++ b/src/nid/opensafd.in
@@ -196,6 +196,22 @@ check_transport() {
  fi
  }
  +wait_for_lockfile_clear() {
+local timeout=10
+local interval=2
+while [ $timeout -gt 0 ]; do
+if [ -e "$lockfile_inprogress" ]; then
+log_warning_msg "opensafd start/stop in 
progress. Wait for lockfile to be removed"
+logger -t $osafprog "opensafd start/stop in 
progress. Wait for lockfile to be removed"

+sleep $interval
+else
+return 0
+fi
+timeout=`expr $timeout - $interval`
+done
+return 1
+}
+
  start() {
  export LD_LIBRARY_PATH=$pkglibdir:$LD_LIBRARY_PATH
  pidofproc -p $amfnd_pid $amfnd_bin > /dev/null 2>&1
@@ -251,8 +267,7 @@ start() {
stop() {
  logger -t $osafprog "Stopping OpenSAF Services"
-
-if [ -e "$lockfile_inprogress" ]; then
+if ! wait_for_lockfile_clear; then
  RETVAL=1
  log_warning_msg "opensafd start/stop already in progress. 
Unable to continue"
  logger -t $osafprog "opensafd start/stop already in 
progress. Unable to continue"











--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Opensaf-devel mailing list
Opensaf-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensaf-devel


Re: [devel] [PATCH 1/1] base: Try again for opensafd stop [#2459]

2017-06-02 Thread Rafael Odzakow
Thanks I am trying to implement the suggestions and will send out a new 
patch soon.



On 06/02/2017 08:51 AM, Hans Nordebäck wrote:

Hi Rafael,

I forgot one thing, not to say that you should change your patch, only 
as an example as we use inotify in opensaf,


the following may also work:

wait_for_lockfile_clear() {
  inotifywait -q -t 20 -e delete_self $lockfile_inprogress
  if [ $? = 2 ]; then
return 1
  else
touch $lockfile_inprogress
return 0
  fi
}

/Hans

On 06/02/2017 07:27 AM, Hans Nordebäck wrote:

ack, code review only.

Minor comments, in current opensafd script, the test and create of 
the lockfile is not atomic, so there is


a window for race. Perhaps we can move the creation of the lockfile 
to function "wait_for_lockfile_clear",


and make the  test and create of the lockfile atomic?

/HansN


On 06/01/2017 02:37 PM, Rafael Odzakow wrote:

Internally opensafd creates a lock file during start/stop to avoid
parallel execution. Wait for this lockfile to be released when a 
call to

opensafd stop is done.
---
  src/nid/opensafd.in | 19 +--
  1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/src/nid/opensafd.in b/src/nid/opensafd.in
index e7683bd7e..df90331a6 100644
--- a/src/nid/opensafd.in
+++ b/src/nid/opensafd.in
@@ -196,6 +196,22 @@ check_transport() {
  fi
  }
  +wait_for_lockfile_clear() {
+local timeout=10
+local interval=2
+while [ $timeout -gt 0 ]; do
+if [ -e "$lockfile_inprogress" ]; then
+log_warning_msg "opensafd start/stop in 
progress. Wait for lockfile to be removed"
+logger -t $osafprog "opensafd start/stop in 
progress. Wait for lockfile to be removed"

+sleep $interval
+else
+return 0
+fi
+timeout=`expr $timeout - $interval`
+done
+return 1
+}
+
  start() {
  export LD_LIBRARY_PATH=$pkglibdir:$LD_LIBRARY_PATH
  pidofproc -p $amfnd_pid $amfnd_bin > /dev/null 2>&1
@@ -251,8 +267,7 @@ start() {
stop() {
  logger -t $osafprog "Stopping OpenSAF Services"
-
-if [ -e "$lockfile_inprogress" ]; then
+if ! wait_for_lockfile_clear; then
  RETVAL=1
  log_warning_msg "opensafd start/stop already in progress. 
Unable to continue"
  logger -t $osafprog "opensafd start/stop already in 
progress. Unable to continue"








--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Opensaf-devel mailing list
Opensaf-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensaf-devel


Re: [devel] [PATCH 1/1] base: Try again for opensafd stop [#2459]

2017-06-01 Thread Hans Nordebäck

Hi Rafael,

I forgot one thing, not to say that you should change your patch, only 
as an example as we use inotify in opensaf,


the following may also work:

wait_for_lockfile_clear() {
  inotifywait -q -t 20 -e delete_self $lockfile_inprogress
  if [ $? = 2 ]; then
return 1
  else
touch $lockfile_inprogress
return 0
  fi
}

/Hans

On 06/02/2017 07:27 AM, Hans Nordebäck wrote:

ack, code review only.

Minor comments, in current opensafd script, the test and create of the 
lockfile is not atomic, so there is


a window for race. Perhaps we can move the creation of the lockfile to 
function "wait_for_lockfile_clear",


and make the  test and create of the lockfile atomic?

/HansN


On 06/01/2017 02:37 PM, Rafael Odzakow wrote:

Internally opensafd creates a lock file during start/stop to avoid
parallel execution. Wait for this lockfile to be released when a call to
opensafd stop is done.
---
  src/nid/opensafd.in | 19 +--
  1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/src/nid/opensafd.in b/src/nid/opensafd.in
index e7683bd7e..df90331a6 100644
--- a/src/nid/opensafd.in
+++ b/src/nid/opensafd.in
@@ -196,6 +196,22 @@ check_transport() {
  fi
  }
  +wait_for_lockfile_clear() {
+local timeout=10
+local interval=2
+while [ $timeout -gt 0 ]; do
+if [ -e "$lockfile_inprogress" ]; then
+log_warning_msg "opensafd start/stop in 
progress. Wait for lockfile to be removed"
+logger -t $osafprog "opensafd start/stop in 
progress. Wait for lockfile to be removed"

+sleep $interval
+else
+return 0
+fi
+timeout=`expr $timeout - $interval`
+done
+return 1
+}
+
  start() {
  export LD_LIBRARY_PATH=$pkglibdir:$LD_LIBRARY_PATH
  pidofproc -p $amfnd_pid $amfnd_bin > /dev/null 2>&1
@@ -251,8 +267,7 @@ start() {
stop() {
  logger -t $osafprog "Stopping OpenSAF Services"
-
-if [ -e "$lockfile_inprogress" ]; then
+if ! wait_for_lockfile_clear; then
  RETVAL=1
  log_warning_msg "opensafd start/stop already in progress. 
Unable to continue"
  logger -t $osafprog "opensafd start/stop already in 
progress. Unable to continue"





--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Opensaf-devel mailing list
Opensaf-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensaf-devel


Re: [devel] [PATCH 1/1] base: Try again for opensafd stop [#2459]

2017-06-01 Thread Hans Nordebäck

ack, code review only.

Minor comments, in current opensafd script, the test and create of the 
lockfile is not atomic, so there is


a window for race. Perhaps we can move the creation of the lockfile to 
function "wait_for_lockfile_clear",


and make the  test and create of the lockfile atomic?

/HansN


On 06/01/2017 02:37 PM, Rafael Odzakow wrote:

Internally opensafd creates a lock file during start/stop to avoid
parallel execution. Wait for this lockfile to be released when a call to
opensafd stop is done.
---
  src/nid/opensafd.in | 19 +--
  1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/src/nid/opensafd.in b/src/nid/opensafd.in
index e7683bd7e..df90331a6 100644
--- a/src/nid/opensafd.in
+++ b/src/nid/opensafd.in
@@ -196,6 +196,22 @@ check_transport() {
fi
  }
  
+wait_for_lockfile_clear() {

+local timeout=10
+local interval=2
+while [ $timeout -gt 0 ]; do
+if [ -e "$lockfile_inprogress" ]; then
+log_warning_msg "opensafd start/stop in progress. Wait for 
lockfile to be removed"
+logger -t $osafprog "opensafd start/stop in progress. Wait for 
lockfile to be removed"
+sleep $interval
+else
+return 0
+fi
+timeout=`expr $timeout - $interval`
+done
+return 1
+}
+
  start() {
export LD_LIBRARY_PATH=$pkglibdir:$LD_LIBRARY_PATH
  pidofproc -p $amfnd_pid $amfnd_bin > /dev/null 2>&1
@@ -251,8 +267,7 @@ start() {
  
  stop() {

logger -t $osafprog "Stopping OpenSAF Services"
-
-   if [ -e "$lockfile_inprogress" ]; then
+if ! wait_for_lockfile_clear; then
RETVAL=1
log_warning_msg "opensafd start/stop already in progress. Unable to 
continue"
logger -t $osafprog "opensafd start/stop already in progress. Unable 
to continue"



--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Opensaf-devel mailing list
Opensaf-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensaf-devel


Re: [devel] [PATCH 1/1] base: Try again for opensafd stop [#2459]

2017-06-01 Thread Anders Widell

Ack with comments.

* Mabe log only once instead of every 2 seconds?

* Fix shellcheck.net warnings:

local timeout=10
^-- SC2039: In POSIX sh, 'local' is undefined.

local interval=2
^-- SC2039: In POSIX sh, 'local' is undefined.

timeout=`expr $timeout - $interval`
^-- SC2006: Use $(..) instead of legacy `..`.
 ^-- SC2003: expr is antiquated. Consider rewriting 
this using $((..)), ${} or [[ ]].


thanks,
Anders Widell

On 06/01/2017 02:37 PM, Rafael Odzakow wrote:

Internally opensafd creates a lock file during start/stop to avoid
parallel execution. Wait for this lockfile to be released when a call to
opensafd stop is done.
---
  src/nid/opensafd.in | 19 +--
  1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/src/nid/opensafd.in b/src/nid/opensafd.in
index e7683bd7e..df90331a6 100644
--- a/src/nid/opensafd.in
+++ b/src/nid/opensafd.in
@@ -196,6 +196,22 @@ check_transport() {
fi
  }
  
+wait_for_lockfile_clear() {

+local timeout=10
+local interval=2
+while [ $timeout -gt 0 ]; do
+if [ -e "$lockfile_inprogress" ]; then
+log_warning_msg "opensafd start/stop in progress. Wait for 
lockfile to be removed"
+logger -t $osafprog "opensafd start/stop in progress. Wait for 
lockfile to be removed"
+sleep $interval
+else
+return 0
+fi
+timeout=`expr $timeout - $interval`
+done
+return 1
+}
+
  start() {
export LD_LIBRARY_PATH=$pkglibdir:$LD_LIBRARY_PATH
  pidofproc -p $amfnd_pid $amfnd_bin > /dev/null 2>&1
@@ -251,8 +267,7 @@ start() {
  
  stop() {

logger -t $osafprog "Stopping OpenSAF Services"
-
-   if [ -e "$lockfile_inprogress" ]; then
+if ! wait_for_lockfile_clear; then
RETVAL=1
log_warning_msg "opensafd start/stop already in progress. Unable to 
continue"
logger -t $osafprog "opensafd start/stop already in progress. Unable 
to continue"


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Opensaf-devel mailing list
Opensaf-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensaf-devel