forked from jmscott/blobio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dev-reboot
79 lines (66 loc) · 1.74 KB
/
dev-reboot
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
#!/bin/bash
#
# Synopsis:
# Reboot blobio servers (not cron) into cleanish development environment.
# Description:
# The script 'dev-reboot' establishes a clean development environment.
# for the biod and flowd servers. Cronjobs are NOT reset.
#
# Before rebooting all blobio servers, the script dev-reboot kills
# biod and flowd processes owned by $USER, copies the example templates
# for profile, blobio.flow and psqlrc files into the directory etc/, and
# the removes all files the directories in spool/, log/ and run/.
#
# Since etc/profile is rewritten to the default in lib/profile.example,
# the script MUST start in the same directory as the directory
# determined by BLOBIO_ROOT in lib/profile.example.
#
# Usage:
# cd $HOME/opt/blobio
# . bash_login
# dev-reboot >dev-reboot.out 2>&1 &
# Note:
# Simulating cron jobs is tricky. Investigate integrating with anacron.
#
PROG=$(basename $0)
log()
{
echo "$(date +'%Y/%m/%d %H:%M:%S'): $PROG#$$: $@"
}
die()
{
log "ERROR: $@" >&2
exit 1
}
leave()
{
log 'good bye, cruel world'
}
reset_etc()
{
log 'resting configs in directory etc/'
while [ "$1" ]; do
F="$1"
shift
LF=lib/$F.example
test -r $LF || die "can not read file: $LF"
EF=etc/$F
log "copy $LF -> $EF"
rm -f $EF || die "rm -f $EF failed"
cp $LF $EF || die "cp $LF $EF failed"
chmod +w $EF || die "chmod $EF failed"
done
}
log 'hello, world'
trap leave EXIT
log "killing processes owned by $USER: biod flowd"
pkill -u $USER biod flowd
log 'zap files in directories: run/ spool/ log/'
(
echo bloody-bsd-xargs-missing-no-run-if-empty
find run spool log -type f -follow |
# don't zap log/dev-reboot.lo
fgrep -v log/dev-reboot.log
) | xargs rm -vf
reset_etc profile psqlrc blobio.flow || exit 1
cron-reboot