]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | #!/bin/bash |
2 | ||
3 | # | |
4 | # test pidfile here | |
5 | # | |
6 | ||
7 | # Includes | |
8 | source $(dirname $0)/detect-build-env-vars.sh | |
c07f9fc5 | 9 | source $CEPH_ROOT/qa/standalone/ceph-helpers.sh |
7c673cae FG |
10 | |
11 | function run() { | |
12 | local dir=$1 | |
13 | shift | |
14 | ||
15 | export CEPH_MON="127.0.0.1:7124" # git grep '\<7124\>' : there must be only one | |
16 | export CEPH_ARGS | |
17 | CEPH_ARGS+="--fsid=$(uuidgen) --auth-supported=none " | |
18 | CEPH_ARGS+="--mon-host=$CEPH_MON " | |
19 | ||
20 | local funcs=${@:-$(set | sed -n -e 's/^\(TEST_[0-9a-z_]*\) .*/\1/p')} | |
21 | for func in $funcs ; do | |
22 | $func $dir || return 1 | |
23 | done | |
24 | } | |
25 | ||
26 | function TEST_without_pidfile() { | |
27 | local dir=$1 | |
28 | setup $dir | |
29 | local data=$dir/osd1 | |
30 | local id=1 | |
31 | ceph-mon \ | |
32 | --id $id \ | |
33 | --mkfs \ | |
34 | --mon-data=$data \ | |
35 | --run-dir=$dir || return 1 | |
c07f9fc5 | 36 | sleep 1 |
7c673cae FG |
37 | expect_failure $dir "ignore empty --pid-file" ceph-mon \ |
38 | -f \ | |
39 | --log-to-stderr \ | |
40 | --pid-file= \ | |
41 | --id $id \ | |
42 | --mon-data=$data \ | |
43 | --run-dir=$dir || return 1 | |
44 | teardown $dir | |
45 | } | |
46 | ||
47 | function TEST_pidfile() { | |
48 | local dir=$1 | |
49 | setup $dir | |
50 | ||
51 | # no daemon can use a pidfile that is owned by another daemon | |
52 | run_mon $dir a || return 1 | |
c07f9fc5 | 53 | run_mon $dir a --log-to-stderr -f 2>&1 | grep "failed to lock pidfile" || return 1 |
7c673cae FG |
54 | |
55 | run_osd $dir 0 || return 1 | |
c07f9fc5 | 56 | activate_osd $dir 0 --log-to-stderr -f 2>&1 | grep "failed to lock pidfile" || return 1 |
7c673cae FG |
57 | |
58 | # when a daemon shutdown, it will not unlink a path different from | |
59 | # the one it owns | |
60 | mv $dir/osd.0.pid $dir/osd.0.pid.old || return 1 | |
61 | cp $dir/osd.0.pid.old $dir/osd.0.pid || return 1 | |
62 | kill_daemons $dir TERM osd.0 || return 1 | |
63 | test -f $dir/osd.0.pid || return 1 | |
64 | ||
65 | # when a daemon starts, it re-uses the pid file if no other daemon | |
66 | # has it locked | |
67 | run_osd $dir 0 || return 1 | |
68 | ! cmp $dir/osd.0.pid $dir/osd.0.pid.old || return 1 | |
69 | ||
70 | # if the pid in the file is different from the pid of the daemon | |
71 | # the file is not removed because it is assumed to be owned by | |
72 | # another daemon | |
73 | mkdir $dir/old | |
74 | cp $dir/osd.0.pid $dir/old/osd.0.pid # so that kill_daemon finds the pid | |
75 | echo 123 > $dir/osd.0.pid | |
76 | kill_daemons $dir/old TERM osd.0 || return 1 | |
77 | test -f $dir/osd.0.pid || return 1 | |
78 | ||
79 | # when the daemon shutdown, it removes its own pid file | |
80 | test -f $dir/mon.a.pid || return 1 | |
81 | kill_daemons $dir TERM mon.a || return 1 | |
82 | ! test -f $dir/mon.a.pid || return 1 | |
83 | ||
84 | teardown $dir || return 1 | |
85 | } | |
86 | ||
87 | main pidfile "$@" | |
88 |