blob: 5b12b400974456dd7c2bc300d518988675eadba1 [file] [log] [blame]
Tomáš Pecka55f64f82020-12-10 19:03:30 +01001#!/usr/bin/env bash
2
3PIDFILE1="./test-merge1.pid"
4PIDFILE2="./test-merge2.pid"
5
6set -x
7
8stop() {
9 for pidfile in "$PIDFILE1" "$PIDFILE2"; do
10 [[ ! -r "$pidfile" ]] && continue # no pidfile
11
12 PID="$(cat "$pidfile")"
13
14 if ps --pid "$PID" >/dev/null; then
15 kill -SIGTERM "$PID" 2>/dev/null # please terminate
16 sleep 0.5
17 while ps --pid "$PID" >/dev/null; do
18 kill -SIGKILL "$PID" 2>/dev/null # shots fired
19 done
20 fi
21 echo "" > "$pidfile"
22 done
23}
24
25start() {
26 rm -f "$PID1.sysrepo" "$PID2.sysrepo" # in case these files already exist
27
28 ./test-sysrepo_test_merge-daemon --subscribe 2>/dev/null 1>/dev/null & # ctest waits here if those file descriptors are open
29 PID1="$!"
30 echo "$PID1" > $PIDFILE1
31
32 ./test-sysrepo_test_merge-daemon --set-item 2>/dev/null 1>/dev/null &
33 PID2="$!"
34 echo "$PID2" > $PIDFILE2
35
36 echo "Started both daemons ("$PID1", "$PID2")" >&2
37 echo "Waiting for sysrepo initialization" >&2
38 while [ ! -e "$PID1.sysrepo" ] && [ ! -e "$PID2.sysrepo" ]; do
39 sleep 0.1
40 done
41 echo "Done" >&2
42
43}
44
45if [ $# -ne 1 ]; then
46 echo "Usage: $0 start|stop" >&2
47 exit 1
48elif [ "$1" == "start" ]; then
49 stop
50 start
51elif [ "$1" == "stop" ]; then
52 stop
53fi
54
55set +x
56exit 0