1 | #!/bin/sh |
---|
2 | |
---|
3 | umask 066 # user read/write |
---|
4 | |
---|
5 | separator() { |
---|
6 | echo "*************************************** $*" |
---|
7 | } |
---|
8 | |
---|
9 | err () { |
---|
10 | separator ERROR 1>&2 |
---|
11 | echo "`basename $0`: $@" 1>&2 |
---|
12 | exit 1 |
---|
13 | } |
---|
14 | |
---|
15 | TMPDIR=~/.arb_tmp/tmp |
---|
16 | mkdir -p $TMPDIR |
---|
17 | chooser="$TMPDIR/arb_pids_${USER}_*" |
---|
18 | |
---|
19 | separator PANIC |
---|
20 | echo " This Module tries to save a running database" |
---|
21 | echo " There may be more than one database server (ARB_NT):" |
---|
22 | echo " --------------------------------" |
---|
23 | |
---|
24 | for i in $chooser ; do |
---|
25 | if [ ! -L "$i" ] ; then |
---|
26 | /bin/echo " - >" `ls $i` "<"; |
---|
27 | fi |
---|
28 | done |
---|
29 | echo " --------------------------------" |
---|
30 | |
---|
31 | separator |
---|
32 | echo "Please choose one line and enter the rightmost number" |
---|
33 | |
---|
34 | read ARB_PID |
---|
35 | if [ ! -f $TMPDIR/arb_pids_${USER}_${ARB_PID} ]; then |
---|
36 | err "Incorrect Choice" |
---|
37 | fi |
---|
38 | |
---|
39 | separator |
---|
40 | echo "Please enter full path (to save DB):" |
---|
41 | read FILE |
---|
42 | |
---|
43 | panicfile="$TMPDIR/arb_panic_${USER}_${ARB_PID}" |
---|
44 | rm -f $panicfile |
---|
45 | echo "$FILE" >$panicfile |
---|
46 | ok=false |
---|
47 | for i in `cat $TMPDIR/arb_pids_${USER}_${ARB_PID}`; do |
---|
48 | echo "[Sending SIGHUP to pid $i]" |
---|
49 | if kill -HUP $i 2>/dev/null; then |
---|
50 | ok=true |
---|
51 | echo "[Process $i accepted HUP]" |
---|
52 | break |
---|
53 | fi |
---|
54 | done |
---|
55 | |
---|
56 | if [ "$ok" = "false" ]; then |
---|
57 | err "Sorry could not find a running server" |
---|
58 | fi |
---|
59 | separator |
---|
60 | echo "Wait until database is saved (or press <ctrl-c> to abort)" |
---|
61 | while [ -f $panicfile ]; do |
---|
62 | echo "[waiting]" |
---|
63 | sleep 1 |
---|
64 | if [ -f $panicfile] ; then |
---|
65 | sleep 1 |
---|
66 | if [ -f $panicfile] ; then |
---|
67 | sleep 1 |
---|
68 | if [ -f $panicfile] ; then |
---|
69 | sleep 1 |
---|
70 | if [ -f $panicfile] ; then |
---|
71 | sleep 1 |
---|
72 | fi |
---|
73 | fi |
---|
74 | fi |
---|
75 | fi |
---|
76 | done |
---|
77 | |
---|
78 | separator |
---|
79 | echo "enter 'kill' if you want to kill the server and its clients" |
---|
80 | echo "enter 'killall' if you want to kill ALL servers and clients" |
---|
81 | |
---|
82 | read ki |
---|
83 | |
---|
84 | if [ "$ki" = "kill" ] ; then |
---|
85 | echo "[Sending SIGTERM to pid $i]" |
---|
86 | kill -TERM $i |
---|
87 | fi |
---|
88 | if [ "$ki" = "killall" ] ; then |
---|
89 | arb_clean killall |
---|
90 | fi |
---|