File: wait_for_process.sh

package info (click to toggle)
mysql-dfsg-5.0 5.0.51a-24%2Blenny5
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 106,168 kB
  • ctags: 94,516
  • sloc: cpp: 447,179; ansic: 411,410; perl: 38,307; sh: 37,449; tcl: 30,484; pascal: 14,851; yacc: 8,559; makefile: 5,078; java: 4,610; xml: 3,953; sql: 2,920; awk: 1,338; asm: 1,061; sed: 772
file content (114 lines) | stat: -rwxr-xr-x 2,619 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/sh

###########################################################################

# NOTE: this script returns 0 (success) even in case of failure (except for
# usage-error). This is because this script is executed under
# mysql-test-run[.pl] and it's better to examine particular problem in log
# file, than just having said that the test case has failed.

###########################################################################

basename=`basename "$0"`
dirname=`dirname "$0"`

###########################################################################

. "$dirname/utils.sh"

###########################################################################

check_started()
{
  if [ ! -r "$pid_path" ]; then
    log_debug "No PID-file ($pid_path) found -- not started."
    return 1
  fi

  new_pid=`cat "$pid_path" 2>/dev/null`
  err_code=$?

  log_debug "err_code: $err_code; new_pid: $new_pid."

  if [ $? -ne 0 -o -z "$new_pid" ]; then
    log_debug "The process was not started."
    return 1
  fi

  log_debug "The process was started."
  return 0
}

###########################################################################

check_stopped()
{
  if [ -r "$pid_path" ]; then
    log_debug "PID-file '$pid_path' exists -- not stopped."
    return 1
  fi

  log_debug "No PID-file ($pid_path) found -- stopped."
  return 0
}

###########################################################################

if [ $# -ne 4 ]; then
  echo "Usage: $basename <pid file path> <total attempts> started|stopped <test id>"
  exit 1
fi

pid_path="$1"
total_attempts="$2"
event="$3"
test_id="$4"
log_file="$MYSQLTEST_VARDIR/log/$test_id.script.log"

log_debug "-- $basename: starting --"
log_debug "pid_path: '$pid_path'"
log_debug "total_attempts: '$total_attempts'"
log_debug "event: '$event'"
log_debug "test_id: '$test_id'"
log_debug "log_file: '$log_file'"

###########################################################################

case "$event" in
  started)
    check_fn='check_started';
    ;;

  stopped)
    check_fn='check_stopped';
    ;;

  *)
    log_error "Invalid third argument ('started' or 'stopped' expected)."
    quit 0
esac

###########################################################################

cur_attempt=1

while true; do

  log_debug "cur_attempt: $cur_attempt."

  if ( eval $check_fn ); then
    log_info "Success: the process has been $event."
    quit 0
  fi

  [ $cur_attempt -ge $total_attempts ] && break

  log_debug "Sleeping for 1 second..."
  sleep 1

  cur_attempt=`expr $cur_attempt + 1`

done

log_error "The process has not been $event in $total_attempts secs."
quit 0