-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreboot-sync-remote
executable file
·75 lines (63 loc) · 1.52 KB
/
reboot-sync-remote
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
#!/usr/bin/env bash
#
# Synopsis:
# Manual reboot of all sync flowd process in $BLOBIO_ROOT/sync/remote/*
# Usage:
# # Standalone
# export BLOBIO_ROOT=/usr/local/blobio
# reboot-sync-remote
#
# # Called from cron-reboot
# reboot-sync-remote
# Note:
# No safety value check for user blobio, which typically is controlled
# by systemd or launchctl.
#
PROG=$(basename $0)
PKILL_USER=$(id -un)
log()
{
echo "$(date +'%Y/%m/%d %H:%M:%S'): $PROG: $@"
}
die()
{
log "ERROR: $@" >&2
exit 1
}
test $# = 0 || die "wrong number of arguments: got $#, expected 0"
log 'hello, world'
trap 'log good bye, cruel world' EXIT
log "BLOBIO_ROOT=$BLOBIO_ROOT"
cd $BLOBIO_ROOT || die "cd $BLOBIO_ROOT failed: exit status=$?"
logr()
{
log "$SYNC_NAME: $@"
}
dieh()
{
die "$SYNC_NAME: $@"
}
find $BLOBIO_ROOT/sync/remote/ -mindepth 1 -maxdepth 1 -type d |
while read SYNC_ROOT; do
log "sync root: $SYNC_ROOT"
SYNC_NAME=$(basename $SYNC_ROOT)
log "sync name: $SYNC_NAME"
cd $SYNC_ROOT || dieh "cd $SYNC_ROOT failed: exit status=$?"
FLOW_PATH=etc/sync-$SYNC_NAME.flow
if [ ! -e $FLOW_PATH ]; then
logr "WARN (ok): no config for flowd: $FLOW_PATH"
continue
fi
# attempt to zap lingering flowd
if [ -r run/flowd.pid ]; then
PID=$(head -1 run/flowd.pid)
logr "run/flowd.pid exists: #$PID"
kill $PID
rm -f run/flowd.*
fi
log "starting sync flowd server: $SYNC_NAME ..."
log "BLOBIO_ROOT for sync flowd: $SYNC_ROOT"
BLOBIO_ROOT=$SYNC_ROOT flowd server etc/sync-$SYNC_NAME.flow &
FLOWD_PID=$!
log "flowd process id: $FLOWD_PID"
done