ctdb-tests: Avoid shellcheck warnings
[samba.git] / ctdb / tests / simple / scripts / local_daemons.bash
1 # Hey Emacs, this is a -*- shell-script -*- !!!  :-)
2
3 hdir="$CTDB_SCRIPTS_HELPER_BINDIR"
4 export CTDB_EVENT_HELPER="${hdir}/ctdb-event"
5
6 if $CTDB_TESTS_ARE_INSTALLED ; then
7         # Find it in $PATH
8         helper="ctdb_local_daemons"
9 else
10         helper="${CTDB_TEST_DIR}/local_daemons.sh"
11 fi
12
13 ctdb_local_daemons="${helper} ${SIMPLE_TESTS_VAR_DIR}"
14
15 # onnode will execute this, which fakes ssh against local daemons
16 export ONNODE_SSH="${ctdb_local_daemons} ssh"
17
18 #######################################
19
20 setup_ctdb ()
21 {
22         local public_addresses=""
23         local no_event_scripts=false
24         local disable_failover=""
25         local reclock_use_command=""
26         case "$1" in
27         --no-public-addresses) public_addresses="/dev/null" ;;
28         --no-event-scripts)    no_event_scripts=true    ;;
29         --disable-failover)    disable_failover="yes"   ;;
30         --reclock-use-command) reclock_use_command="yes" ;;
31         esac
32
33         $ctdb_local_daemons setup \
34                 -n "$TEST_LOCAL_DAEMONS" \
35                 ${disable_failover:+-F} \
36                 ${public_addresses:+-P} ${public_addresses} \
37                 ${CTDB_USE_IPV6:+-6} \
38                 ${reclock_use_command:+-R} \
39                 ${TEST_SOCKET_WRAPPER_SO_PATH:+-S ${TEST_SOCKET_WRAPPER_SO_PATH}}
40         # Burying the above in an if-statement condition reduces readability.
41         # shellcheck disable=SC2181
42         if [ $? -ne 0 ] ; then
43                 exit 1
44         fi
45
46         local pnn
47         for pnn in $(seq 0 $((TEST_LOCAL_DAEMONS - 1))) ; do
48                 if $no_event_scripts ; then
49                         rm -vf "${CTDB_BASE}/events/legacy/"*
50                 fi
51         done
52 }
53
54 start_ctdb_1 ()
55 {
56         local pnn="$1"
57
58         $ctdb_local_daemons start "$pnn"
59 }
60
61 ctdb_start_all ()
62 {
63         $ctdb_local_daemons start "all"
64 }
65
66 stop_ctdb_1 ()
67 {
68         local pnn="$1"
69
70         $ctdb_local_daemons stop "$pnn"
71 }
72
73 ctdb_stop_all ()
74 {
75         $ctdb_local_daemons stop "all"
76 }
77
78 restart_ctdb_1 ()
79 {
80         stop_ctdb_1 "$1"
81         start_ctdb_1 "$1"
82 }
83
84 # onnode just needs the nodes file, so use the common one
85 export CTDB_BASE="$SIMPLE_TESTS_VAR_DIR"