blob: c839b9823c32400e7d0cdfd5d138df1af5de2000 [file] [log] [blame]
Tomáš Peckabe797072022-07-15 20:45:52 +02001#!/usr/bin/env bash
2
3PIDFILE="./test-alarms.pid"
4
5set -x
6
7stop() {
8 [[ ! -r "$PIDFILE" ]] && return 0 # no pidfile
9
10 PID="$(cat "$PIDFILE")"
11
12 if ps --pid "$PID" >/dev/null; then
13 kill -15 -- "$PID" 2>/dev/null # please terminate
14 sleep 0.5
15 while ps --pid "$PID" >/dev/null; do
16 kill -9 -- "$PID" 2>/dev/null # shots fired
17 done
18 fi
19 echo "" > "$PIDFILE"
20}
21
22# $1 ... path to daemon
23start() {
24 rm -f "$PIDFILE" # in case these files already exist
25
26 if [[ ! -x "$1" ]]; then
27 echo "$1 is not executable" >&2
28 return 1
29 fi
30
31 $1 --sysrepo-log-level=5 1>$2 2>&1 &
32 PID="$!"
33 echo "$PID" > $PIDFILE
34
35 # wait for init
36 sleep 2
37
38 echo "Started $1 (pid=$PID)" >&2
39}
40
41help() {
42 echo "Usage:" >&2
43 echo " $1 start PATH_TO_SYSREPO_IETF_ALARMSD LOGFILE" >&2
44 echo " $1 stop" >&2
45}
46
47if [[ "$1" == "start" && $# == 3 ]]; then
48 stop
49 start "$2" "$3"
50elif [[ "$1" == "stop" && $# == 1 ]]; then
51 stop
52else
53 help
54 exit 1
55fi