~percona-toolkit-dev/percona-toolkit/2.0

« back to all changes in this revision

Viewing changes to t/lib/bash/daemon.sh

  • Committer: Daniel Nichter
  • Date: 2011-12-27 22:37:09 UTC
  • mfrom: (109.2.27 bash-tool-libs)
  • Revision ID: daniel@percona.com-20111227223709-v227ijlpw51qxl5z
MergeĀ lp:~daniel-nichter/percona-toolkit/bash-tool-libs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env bash
 
2
 
 
3
TESTS=7
 
4
 
 
5
TMPDIR="$TEST_TMPDIR"
 
6
local file="$TMPDIR/pid-file"
 
7
 
 
8
source "$LIB_DIR/log_warn_die.sh"
 
9
source "$LIB_DIR/daemon.sh"
 
10
 
 
11
cmd_ok \
 
12
   "test ! -f $file" \
 
13
   "PID file doesn't exist"
 
14
 
 
15
make_pid_file $file $$
 
16
 
 
17
cmd_ok \
 
18
   "test -f $file" \
 
19
   "PID file created"
 
20
 
 
21
local pid=`cat $file`
 
22
is \
 
23
   "$pid" \
 
24
   "$$" \
 
25
   "Correct PID"
 
26
 
 
27
remove_pid_file $file
 
28
 
 
29
cmd_ok \
 
30
   "test ! -f $file" \
 
31
   "PID file removed"
 
32
 
 
33
# ###########################################################################
 
34
# PID file already exists and proc is running.
 
35
# ###########################################################################
 
36
echo $$ > $file
 
37
 
 
38
(
 
39
   make_pid_file $file $$ >$TMPDIR/output 2>&1
 
40
)
 
41
 
 
42
cmd_ok \
 
43
   "grep -q \"PID file /tmp/percona-toolkit.test/pid-file already exists and its PID ($$) is running\" $TMPDIR/output" \
 
44
   "Does not overwrite PID file is PID is running"
 
45
 
 
46
echo 999999 > $file
 
47
 
 
48
make_pid_file $file $$ >$TMPDIR/output 2>&1
 
49
 
 
50
cmd_ok \
 
51
   "grep -q 'Overwriting PID file /tmp/percona-toolkit.test/pid-file because its PID (999999) is not running' $TMPDIR/output" \
 
52
   "Overwrites PID file if PID is not running"
 
53
 
 
54
pid=`cat $file`
 
55
is \
 
56
   "$pid" \
 
57
   "$$" \
 
58
   "Correct PID"
 
59
 
 
60
rm $file
 
61
rm $TMPDIR/output
 
62
 
 
63
# ###########################################################################
 
64
# Done.
 
65
# ###########################################################################