Tomáš Pecka | 55f64f8 | 2020-12-10 19:03:30 +0100 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | PIDFILE1="./test-merge1.pid" |
| 4 | PIDFILE2="./test-merge2.pid" |
| 5 | |
| 6 | set -x |
| 7 | |
| 8 | stop() { |
| 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 | |
| 25 | start() { |
| 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 | |
| 45 | if [ $# -ne 1 ]; then |
| 46 | echo "Usage: $0 start|stop" >&2 |
| 47 | exit 1 |
| 48 | elif [ "$1" == "start" ]; then |
| 49 | stop |
| 50 | start |
| 51 | elif [ "$1" == "stop" ]; then |
| 52 | stop |
| 53 | fi |
| 54 | |
| 55 | set +x |
| 56 | exit 0 |