-
Notifications
You must be signed in to change notification settings - Fork 1
/
stop-flowd
executable file
·79 lines (64 loc) · 1.56 KB
/
stop-flowd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env bash
#
# Synopsis:
# Kill a flowd process for a schema, possibly going nuclear
# Usage:
# kill-flowd <schema>
# Exit Status:
# 0 running flowd probably killed and files run/flowd.* removed.
# 1 unexpected error
# Note:
# In leave() "rm -f called a bit to early"
#
PROG=$(basename $0)
SCHEMA_ROOT=
# pause after either stopping or starting flowd
log()
{
MSG=$@
test -n "$SCHEMA" && MSG="$SCHEMA: $MSG"
echo "$(date +'%Y-%m-%d %H:%M:%S'): $PROG: $MSG"
}
die()
{
log "ERROR: $@" >&2
exit 1
}
leave()
{
test $(basename $(pwd)) = $SCHEMA && rm -f run/flowd.*
log 'good bye, cruel world'
}
test $# = 1 || die 'wrong number of arguments'
SCHEMA=$1
log 'hello, world'
trap leave EXIT
test -n "$SETSPACE_ROOT" ||
die "environment variable not defined: SETSPACE_ROOT"
log "SETSPACE_ROOT=$SETSPACE_ROOT"
cd "$SETSPACE_ROOT" || die "cd $SETSPACE_ROOT failed"
. etc/profile
# goto to root of schema directory in $SETSPACE_ROOT/schema/$SCHEMA
# source in a local etc/profile for the schema
SCHEMA_ROOT=schema/$SCHEMA
test -d "$SCHEMA_ROOT" || die "missing schema dir: $SCHEMA_ROOT"
cd $SCHEMA_ROOT || die "cd $SCHEMA_ROOT failed: exit status=$?"
test -e etc/profile && . etc/profile
test -d run || die "missing run directory: $(pwd)/run/"
# check for pid file of flowd process
FLOWD_PID=run/flowd.pid
if [ ! -e $FLOWD_PID ]; then
log "WARN: no pid file (ok): $FLOWD_PID"
exit 0
fi
test -s $FLOWD_PID || die "empty file: $FLOWD_PID"
PID=$(head -1 $FLOWD_PID)
case "$PID" in
[0-9]*)
log "kill flowd: #$PID"
kill $PID
;;
*)
die "no pid in flowd.pid: $PID"
;;
esac